package cn.fl.project.controller;

import cmm.comm.facade.framework.api.ISysCtrlCfgApiService;
import cmm.comm.facade.framework.api.ISysDictionaryApiService;
import cmm.comm.facade.framework.condition.SysCtrlCfgQueryCondition;
import cmm.comm.facade.framework.dto.SysDictionaryDTO;
import cmm.mid.core.framework.dto.BaseParamDTO;
import cmm.mid.core.framework.dto.DataResultDTO;
import cmm.mid.core.framework.page.DataResultVO;
import cmm.mid.core.framework.page.KeyValueVO;
import cmm.mid.core.framework.page.ListPageVO;
import cmm.mid.core.framework.page.Pager;
import cmm.web.core.framework.controller.BaseController;
import cn.cmm.base.framework.constant.BaseConstant;
import cn.cmm.base.framework.constant.BaseExceptionConstant;
import cn.cmm.base.framework.exception.BaseException;
import cn.cmm.base.framework.utils.CollectionUtils;
import cn.cmm.base.framework.utils.DecimalUtils;
import cn.cmm.base.framework.utils.PropertiesUtils;
import cn.cmm.base.framework.utils.StringUtils;
import cn.fl.capital.constant.CapitalConstant;
import cn.fl.framework.base.constant.WebBaseConstant;
import cn.fl.framework.base.context.CurrentThreadContext;
import cn.fl.framework.constant.DictionaryConstant;
import cn.fl.index.api.IPrjPlcyIndexApiService;
import cn.fl.index.constant.PrjPlcyIndexConstant;
import cn.fl.insroute.service.IInsRouteBscInfoService;
import cn.fl.insroute.vo.InsRouteBscInfoVO;
import cn.fl.insroute.vo.InsRouteInsResVO;
import cn.fl.insroute.vo.InsRoutePrdInfoVO;
import cn.fl.insroute.vo.InsRoutePrpsFeeVO;
import cn.fl.preinsroute.service.IPreRouteInsResService;
import cn.fl.preinsroute.vo.PreRouteInsResVO;
import cn.fl.preloan.enums.LogBusinessTypeEnum;
import cn.fl.product.service.IPrdBscInfoService;
import cn.fl.product.service.IPrdCarInfoService;
import cn.fl.product.vo.PrdBscInfoVO;
import cn.fl.product.vo.PrdCarInfoVO;
import cn.fl.project.ProjectUtils;
import cn.fl.project.condition.*;
import cn.fl.project.constant.*;
import cn.fl.project.dto.PrjBscInfoDTO;
import cn.fl.project.service.*;
import cn.fl.project.transform.PrjBscInfoVOTransform;
import cn.fl.project.utils.GuidePcEditUtil;
import cn.fl.project.vo.*;
import cn.fl.ref.fribaseinfo.service.IFriBaseInfoService;
import cn.fl.ref.fribaseinfo.utils.FundRasInsNmChangeUtil;
import cn.fl.ref.fribaseinfo.vo.FriBaseInfoVO;
import cn.fl.system.constant.SysLogConstant;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.lionbridge.log.ext.ExtSlf4jLogger;
import com.lionbridge.log.ext.ExtSlf4jLoggerBuilder;
import com.lionbridge.log.ext.LogTypeEnum;
import fl.constant.facade.framework.constant.SysCtrlCfgConstant;
import fl.ref.fribaseinfo.condition.FriBaseInfoQueryCondition;
import fl.riskctrl.facade.externalinterface.service.api.IExternalRcCstBscInfoSearchApiService;
import fl.riskctrl.facade.externalinterface.service.dto.RcRskLvlAndSplStarResult;
import fl.riskctrl.facade.riskctrl.riskctrlsingle.api.IRiskCtrlSingleApiService;
import fl.riskctrl.facade.riskctrl.riskctrlsingle.condition.RiskCtrlSingleResult;
import fl.spl.facade.framework.constant.SplSystemConstant;
import fl.spl.facade.store.api.ISplPropInfoApiService;
import lombok.extern.slf4j.Slf4j;
import net.sf.json.JSONArray;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal;
import java.util.*;

/**
 * @Description: 项目报价方案表 控制层
 */
@Slf4j
@Controller
@RequestMapping("/project/prjquatprps")
public class PrjQuatPrpsController extends BaseController {
	private static ExtSlf4jLogger logger = ExtSlf4jLoggerBuilder.create()
			.setLogger(log).setBusinessType(LogBusinessTypeEnum.QUOTATION_SCHEME.getCode())
			.setSubBusinessType(LogBusinessTypeEnum.QUOTATION_SCHEME.getCode())
			.setLogType(LogTypeEnum.BUSINESS).build().setKeywords("PrjQuatPrps");
	/**
	 * PrjQuatPrps 服务层BEAN
	 */
	@Autowired
	private IPrjQuatPrpsService prjQuatPrpsService;
	@Autowired
	private IPrjQuatPrpsCfgMService prjQuatPrpsCfgMService;
	@Autowired
	private IPrjQuatPrpsCfgAiService prjQuatPrpsCfgAiService;
	@Autowired
	private IPrjQuatPrpsCfgDService prjQuatPrpsCfgDService;
	@Autowired
	private IPrjBscInfoService prjBscInfoService;
	@Autowired
	private IPrjPrdBscInfoService prjPrdBscInfoService;
	@Autowired
	private ISysDictionaryApiService  sysDictionaryApiService;
	@Autowired
	private IPrdCarInfoService prdCarInfoService;
	@Autowired
	private IPrdBscInfoService prdBscInfoService;
	@Autowired
	private IPrjQuatPrpsRebService prjQuatPrpsRebService;
	@Autowired
	private IPrjPrdDtlService prjPrdDtlService;
	@Autowired
	private IPrjPrdPaySchMService prjPrdPaySchMService;
	@Autowired
	private IPrjPlcyIndexApiService prjPlcyIndexApiService;

	@Autowired
	private IPrjQuatPrpsZGService prjQuatPrpsZGService;
    @Autowired
    private ICalQuatPrpsService calQuatPrpsService;
    @Autowired
    private IRiskCtrlSingleApiService riskCtrlSingleApiService;
	@Autowired
	private IInsRouteBscInfoService insRouteBscInfoService;
	@Autowired
	private IPrjPayInfoForSmallLoanService prjPayInfoForSmallLoanService;
	@Autowired
	private IExternalRcCstBscInfoSearchApiService externalRcCstBscInfoSearchApiService ;
	@Autowired
	ISysCtrlCfgApiService sysCtrlCfgApiService;
	@Autowired
	private ISplPropInfoApiService iSplPropInfoApiService;
	@Autowired
	private IFriBaseInfoService friBaseInfoService;//融资机构基础信息表
	@Autowired
	private IPreRouteInsResService preRouteInsResService;

	/**
	 * 到CDS決策引擎頁面
	 */
	@RequestMapping(value = "/toPrjPlcyIndex.do", method = { RequestMethod.GET})
	public ModelAndView toPrjPlcyIndex(HttpServletRequest request, HttpServletResponse response) {
		ModelAndView view = new ModelAndView("project/prjbscinfo/prjPlcyIndex");
		String prjId = request.getParameter("prjId");//项目ID
		view.addObject("prjId",prjId);
		if (StringUtils.isNotEmpty(prjId)){
            PrjBscInfoVO prjBscInfoVO = this.prjBscInfoService.selectById(Long.valueOf(prjId));
            if (prjBscInfoVO != null && prjBscInfoVO.getAuditInfo() != null){
            	String auditInfo = prjBscInfoVO.getAuditInfo();
                //系统判断方案审核结果
				String replaceAll = auditInfo.replaceAll(">>", "</br></br>");
				view = this.splitCdsResult(view,replaceAll);
				view.addObject("auditInfo", replaceAll);
            }
        }
		return view;
	}

	private ModelAndView splitCdsResult(ModelAndView view, String result) {
		//产品方案
		String productPrps = "";
		//区域政策
		String areaPolicy = "";
		//阶梯政策
		String ladderPolicy = "";
		if(result.contains("区域政策")){
			productPrps = result.substring(0,result.indexOf("区域政策"));
			if(result.contains("阶梯政策")){
				areaPolicy = result.substring(result.indexOf("区域政策"),result.indexOf("阶梯政策"));
				ladderPolicy = result.substring(result.indexOf("阶梯政策"),result.length());
			}else{
				areaPolicy = result.substring(result.indexOf("区域政策"),result.length());
			}
		}else{
			productPrps = result;
		}
		//根据中英文封号冒号 替换换行符
		productPrps = productPrps.replaceAll(":", ":\r\n").replaceAll(";", ";\r\n")
				.replaceAll("：", "：\r\n").replaceAll("；", "；\r\n");
		areaPolicy = areaPolicy.replaceAll(":", ":\r\n").replaceAll(";", ";\r\n")
				.replaceAll("：", "：\r\n").replaceAll("；", "；\r\n");
		ladderPolicy = ladderPolicy.replaceAll(":", ":\r\n").replaceAll(";", ";\r\n")
				.replaceAll("：", "：\r\n").replaceAll("；", "；\r\n");
		String[] productPrpsArray = productPrps.split("\r\n");
		String[] areaPolicyArray = areaPolicy.split("\r\n");
		String[] ladderPolicyArray = ladderPolicy.split("\r\n");
		List<String> productPrpsList = Arrays.asList(productPrpsArray).subList(0,productPrpsArray.length);
		List<String> areaPolicyList = new ArrayList<>();
		List<String> ladderPolicyList = new ArrayList<>();
		if(areaPolicyArray.length > 1){
			areaPolicyList = Arrays.asList(areaPolicyArray).subList(1,areaPolicyArray.length);
		}
		if(ladderPolicyArray.length > 1){
			ladderPolicyList = Arrays.asList(ladderPolicyArray).subList(1,ladderPolicyArray.length);
		}
		view.addObject("productPrpsList",productPrpsList);
		view.addObject("areaPolicyList",areaPolicyList);
		view.addObject("ladderPolicyList",ladderPolicyList);
		return view;
	}

	/**
	 * 查詢風控決策
	 */
	@RequestMapping(value = "/searchCheckPrjPlcyIndex.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object searchCheckPrjPlcyIndex(HttpServletRequest request, HttpServletResponse response) {
		String prjId = request.getParameter("prjId");//项目ID
		DataResultDTO result = null;
		if (StringUtils.isNotEmpty(prjId)){
			result = prjPlcyIndexApiService.searchCheckPrjPlcyIndex(Long.valueOf(prjId), false);
		}
		logger.info("CDS决策引擎，prjId:{}",prjId);
		return result;
	}


	/**
	 * 到列表页面
	 */
	@RequestMapping(value = "/toListPage.do", method = { RequestMethod.GET})
	public ModelAndView toListPage(HttpServletRequest request, HttpServletResponse response) {
		String prjId = request.getParameter("prjId");//项目ID
		String detailFlag = request.getParameter("detailFlag");
		String isFlow  = request.getParameter("isFlow");
		ModelAndView view = new ModelAndView("project/prjquatprps/prjQuatPrpsList");
		List<KeyValueVO> yesNoCdList = this.prjQuatPrpsCfgMService.searchYesOrNoCdList();
		PrjBscInfoVO prjbsc = this.prjBscInfoService.selectById(Long.valueOf(prjId));
		Integer isShowAdd = BaseConstant.IS_YESNO_NO;
		if(prjbsc.getBuOrgCd().equals(PrjBscInfoConstant.CODE_BU_ORG_CD_XNY)){
			//判断是否可以重新生成方案信息
			boolean flag = this.prjQuatPrpsService.getPrjQuatPrpsTempByPrjId(prjbsc.getId());
			if(flag){
				isShowAdd =  BaseConstant.IS_YESNO_YES;
			}
		}
		view.addObject("yesOrNoCdListJSON",JSON.toJSONString(yesNoCdList) );//是否
		view.addObject("isShowAdd",isShowAdd);//是否
		view.addObject("prjId",prjId);//是否
		view.addObject("detailFlag",detailFlag);
		view.addObject("buOrgCd",prjbsc.getBuOrgCd());
		view.addObject("insCode", prjbsc.getInsCode());
		view.addObject("isFlow", isFlow);
		
		//********流程参数开始********//
		String preTaskIds = request.getParameter("preTaskIds");//流程上一个节点任务ID,多个以逗号分割.
		String pInstId = request.getParameter("pInstId");//流程实例ID
		view.addObject("pInstId", pInstId);
		view.addObject("preTaskIds", preTaskIds);
		//********流程参数结束********//
		logger.info("跳转到列表页面,prjId:{}",prjId);
		return view;
	}

	/**
	 * 到选择方案列表页面
	 */
	@RequestMapping(value = "/toPrjQuatPrpsCfgMPage.do", method = { RequestMethod.GET})
	public ModelAndView toPrjQuatPrpsCfgMPage(HttpServletRequest request, HttpServletResponse response) {
		ModelAndView view = new ModelAndView("project/prjquatprps/prjQuatPrpsCgfMList");
		String prjId = request.getParameter("prjId");//项目ID
		//
		PrjBscInfoVO prjbsc = this.prjBscInfoService.selectById(Long.valueOf(prjId));
		view.addObject("prjId",prjId );//项目ID
		view.addObject("buOrgCd", prjbsc.getBuOrgCd());
		view.addObject("insCode", prjbsc.getInsCode());
		logger.info("跳转到列表页面prjId:{}",prjId);
		return view;
	}
	/**
	 * 到添加页面
	 */
	@RequestMapping(value = "/toAddPage.do", method = { RequestMethod.GET, RequestMethod.POST })
	public ModelAndView toModifyPage(HttpServletRequest request, HttpServletResponse response) {
		String prjId = request.getParameter("prjId");
		String id = request.getParameter("id");
		String isFlow = request.getParameter("isFlow");//是否在流程中提示信息
		String detailFlag = request.getParameter("detailFlag");

		ModelAndView view = new ModelAndView("project/prjquatprps/prjQuatPrpsAdd");
		String prpsCfgId=request.getParameter("prpsCfgId");
		String prpsTypCd = request.getParameter("prpsTypCd");
		String isLowBiz = request.getParameter("isLowBiz");//是否低息
		String isLowBizFlag = BaseConstant.IS_YESNO_NO_STR;//是否显示低息 0-不显示,1-显示 默认不显示
		view.addObject("isLowBiz",isLowBiz);
		PrjQuatPrpsCfgMVO 	quatPrps = null;
		List<PrjQuatPrpsCfgDVO> list = null;
		Double defSplitPct = 0d;
		int prdNum = 0;
		double totalPrdAmt=0d;
        double totalRsrvPc = 0d;
		double mfrDiscountRate = 0d;
		double quatRsrvPc = 0d;//方案配置留购价
		Integer isAllowChg = 1; //留购价是否可编辑
		int isShowBp = BaseConstant.IS_YESNO_YES;//是否显示包牌价字段
		Boolean isDealer = false;//是否为经销商
		//Boolean isShowSpecialBusiness = false;//是否展示特殊业务下拉列表
		Boolean isSupportLowRateForDealers = false;//经销商是否支持低息
		Long splId = null;
		PrjBscInfoVO bscInfoVO = this.prjBscInfoService.selectById(Long.valueOf(prjId));
		String prjTypCd = bscInfoVO.getPrjTypCd();
		String dsCd = bscInfoVO.getDsCd();
		/**
		 * REQ-14557 资管机构报价方案【高保证金抵租金】字段展示逻辑优化
		 * 调整从字典配置中获取
		 */
		if (PrjBscInfoConstant.CODE_BU_ORG_CD_ZK.equals(bscInfoVO.getBuOrgCd())
			&& (PrjBscInfoConstant.PRJ_TYP_CD_CPYW.equals(prjTypCd) || PrjBscInfoConstant.PRJ_TYP_CD_CTYW.equals(prjTypCd))
		) {
			Map<String, String> isLowBizMap = this.sysDictionaryApiService.searchGroupToMap(CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd(), "PRJ0162");
			logger.info("是否低息isLowBizMap={}",JSON.toJSONString(isLowBizMap));
			if (CollectionUtils.isMapNotEmpty(isLowBizMap)) {
				if (isLowBizMap.containsKey(bscInfoVO.getInsCode())) {
					isLowBizFlag = BaseConstant.IS_YESNO_YES_STR;
				}
			}
		}
		view.addObject("isLowBizFlag",isLowBizFlag);
		view.addObject("dsCd",dsCd);

		/**
		 * 车辆参考价是否可编辑标志,0-否,1-是
		 * 这里要定义车辆参考价是否可编辑规则
		 */
		PrjBscInfoDTO prjBscInfoDTO = PrjBscInfoVOTransform.toDTO(bscInfoVO);
		//根据项目ID查看是否关联路由信息
		InsRouteBscInfoVO insRouteBscInfoVOTemp = this.insRouteBscInfoService.searchListByPrjId(prjBscInfoDTO.getId());
		logger.info("toAddPage 根据项目ID查看是否关联路由信息,项目ID={},路由结果={}", prjBscInfoDTO.getId(),JSON.toJSONString(insRouteBscInfoVOTemp));
		if (insRouteBscInfoVOTemp != null) {
			prjBscInfoDTO.setInsPrjRelateFlag(BaseConstant.IS_YESNO_YES_STR);
		}
		String guidePcEditFlag = GuidePcEditUtil.getGuidePcEditFlag(prjBscInfoDTO);

		//合同额替换
		double totalPrdAmtReplace = 0d;
		Double mediationFeeAmtSum = 0d;

		if(StringUtils.isNotEmpty(prpsCfgId)){
			quatPrps = 	this.prjQuatPrpsCfgMService.selectById(Long.valueOf(prpsCfgId));
			Pager page = new Pager();

			PrjQuatPrpsCfgDQueryCondition qc = new PrjQuatPrpsCfgDQueryCondition();
			page.setEveryPage(Integer.MAX_VALUE);//最大数据量
			qc.setPrpsCfgId(Long.valueOf(prpsCfgId));
			page.setCondition(qc);
			Pager pager = this.prjQuatPrpsCfgDService.searchListPage(page);
			list = (List<PrjQuatPrpsCfgDVO>) pager.getResultList();
			logger.info("toAddPage方案费用项初始化.路由前结果list:{}", JSON.toJSONString(list));
			Integer isInsBiz = bscInfoVO.getIsInsBiz();
			if(!(PrjBscInfoConstant.CODE_BU_ORG_CD_XNY.equals(bscInfoVO.getBuOrgCd()) && !(BaseConstant.IS_YESNO_YES == isInsBiz))){
				InsRouteBscInfoVO insRouteBscInfoVO = this.insRouteBscInfoService.searchListByPrjId(Long.valueOf(prjId));
				logger.info("toAddPage方案费用项初始化.路由前结果listinsRouteBscInfoVO:{}", JSON.toJSONString(insRouteBscInfoVO));

				List<InsRoutePrpsFeeVO> insRoutePrpsFeeVOList = new ArrayList<InsRoutePrpsFeeVO>();
				if(insRouteBscInfoVO != null){
					quatPrps.setLsPd(insRouteBscInfoVO.getLsPd());
					view.addObject("isBp", insRouteBscInfoVO.getIsBp());//是否包牌
					view.addObject("annIntRatePct", insRouteBscInfoVO.getAnnIntRatePct());//租赁年利率
					if(PrjBscInfoConstant.PRJ_TYP_CD_CDDYWUL.equals(prjTypCd) || PrjBscInfoConstant.PRJ_TYP_CD_ESCJYD.equals(prjTypCd) || PrjBscInfoConstant.PRJ_TYP_CD_OWNJYD.equals(prjTypCd)){
						quatPrps.setPayWayCd(insRouteBscInfoVO.getPayWayCd());
					}
					insRoutePrpsFeeVOList = insRouteBscInfoVO.getInsRoutePrpsFeeVOList();
				}
				if(PrjBscInfoConstant.CODE_BU_ORG_CD_QK.equals(bscInfoVO.getBuOrgCd())){
					quatPrps.setLsPd(36l);
					view.addObject("isBp", PrjQuatPrpsConstant.CODE_IS_BP_2);//是否包牌
					if (quatPrps.getPrpsCfgNm().contains("东风")) {
						view.addObject("annIntRatePct", 11.7);//租赁年利率
					}else{
						view.addObject("annIntRatePct", 10);//租赁年利率
					}
				}
				List<InsRoutePrdInfoVO> insRoutePrdInfoVOList = insRouteBscInfoVO.getInsRoutePrdInfoVOList();
				if(CollectionUtils.isNotEmpty(insRoutePrdInfoVOList)){
					for (InsRoutePrdInfoVO insRoutePrdInfoVO : insRoutePrdInfoVOList) {
						mediationFeeAmtSum += DecimalUtils.convertFenToYuan(insRoutePrdInfoVO.getMediationFeeAmt()*insRoutePrdInfoVO.getPrdQty());

					}
				}
				Double actAmt = 0d;
				boolean fee76 = false;
				for (PrjQuatPrpsCfgDVO prjQuatPrpsCfgDVO : list) {
					String feeTypCd = prjQuatPrpsCfgDVO.getFeeTypCd();
					//留购价
					if(StringUtils.isNotEmpty(feeTypCd) && PrjQuatPrpsFeeConstant.PRJ_FEE_TYP_PURCHASE.equals(feeTypCd)){
						quatRsrvPc = prjQuatPrpsCfgDVO.getFixedAmt();
						isAllowChg = prjQuatPrpsCfgDVO.getIsAllowChg();
					}
					if(PrjQuatPrpsFeeConstant.FEE_TYP_CD_76.equals(feeTypCd)){
						fee76 = true;
						if(PrjBscInfoConstant.PRJ_TYP_CD_CDDYWUL.equals(prjTypCd) || PrjBscInfoConstant.PRJ_TYP_CD_ESCJYD.equals(prjTypCd) || PrjBscInfoConstant.PRJ_TYP_CD_OWNJYD.equals(prjTypCd)){
							prjQuatPrpsCfgDVO.setCntWayCd(PrjQuatPrpsConstant.CODE_PRJ_QUAT_CNT_WAY_CONT);
							prjQuatPrpsCfgDVO.setCntWayCdNm("计入合同额");
							prjQuatPrpsCfgDVO.setIsAllowChg(BaseConstant.IS_YESNO_NO);
						}else{
							prjQuatPrpsCfgDVO.setCntWayCd(PrjQuatPrpsConstant.CODE_PRJ_QUAT_CNT_WAY_OTH);
							prjQuatPrpsCfgDVO.setCntWayCdNm("其他费用");
						}
						prjQuatPrpsCfgDVO.setFixedAmt(mediationFeeAmtSum);
						prjQuatPrpsCfgDVO.setIsFixedAmt(BaseConstant.IS_YESNO_YES);
						prjQuatPrpsCfgDVO.setIsFixedAmtNm("是");
					}
					if(StringUtils.isNotEmpty(feeTypCd)
							&& (PrjQuatPrpsFeeConstant.FEE_TYP_CD_01.equals(feeTypCd)
							|| PrjQuatPrpsFeeConstant.FEE_TYP_CD_02.equals(feeTypCd)
							|| PrjQuatPrpsFeeConstant.FEE_TYP_CD_63.equals(feeTypCd)
							|| PrjQuatPrpsFeeConstant.FEE_TYP_CD_64.equals(feeTypCd))){
						if(CollectionUtils.isNotEmpty(insRoutePrpsFeeVOList)){
							for (InsRoutePrpsFeeVO insRoutePrpsFeeVO : insRoutePrpsFeeVOList) {
								if(PrjQuatPrpsFeeConstant.FEE_TYP_CD_01.equals(insRoutePrpsFeeVO.getFeeTypCd())){
									actAmt = insRouteBscInfoVO.getContAmt() - insRoutePrpsFeeVO.getFeeAmt();
								}
							}
							for (InsRoutePrpsFeeVO insRoutePrpsFeeVO : insRoutePrpsFeeVOList) {
								if(feeTypCd.equals(insRoutePrpsFeeVO.getFeeTypCd())){
									if(null!=insRoutePrpsFeeVO.getFeeAmt()){
										prjQuatPrpsCfgDVO.setFixedAmt(DecimalUtils.round(insRoutePrpsFeeVO.getFeeAmt()/100,2,BigDecimal.ROUND_HALF_UP));
									}
									if(null!=insRoutePrpsFeeVO.getFeePct() && insRoutePrpsFeeVO.getFeePct().doubleValue() != 0){
										prjQuatPrpsCfgDVO.setFeePct(insRoutePrpsFeeVO.getFeePct());
									}
									if(null!=insRoutePrpsFeeVO.getCntWayCd()){
										prjQuatPrpsCfgDVO.setCntWayCd(insRoutePrpsFeeVO.getCntWayCd());
									}
									if(null!=insRoutePrpsFeeVO.getIsFixedAmt()){
										prjQuatPrpsCfgDVO.setIsFixedAmt(insRoutePrpsFeeVO.getIsFixedAmt());
									}
									if(PrjQuatPrpsFeeConstant.FEE_TYP_CD_02.equals(feeTypCd)){
										if(StringUtils.isNotBlank(insRoutePrpsFeeVO.getCalBaseCd())
												&& !((insRoutePrpsFeeVO.getCalBaseCd()).equals(prjQuatPrpsCfgDVO.getCalBaseCd()))){
											if(PrjQuatPrpsConstant.CODE_CAL_BASE_CONTRACT.equals(prjQuatPrpsCfgDVO.getCalBaseCd())){
												if(null!=insRoutePrpsFeeVO.getFeeAmt()){
													prjQuatPrpsCfgDVO.setFeePct(DecimalUtils.div(insRoutePrpsFeeVO.getFeeAmt(),insRouteBscInfoVO.getContAmt(),10)*100);
												}
											}else if(PrjQuatPrpsConstant.CODE_CAL_BASE_FINANCING.equals(prjQuatPrpsCfgDVO.getCalBaseCd())){
												prjQuatPrpsCfgDVO.setFeePct(DecimalUtils.div(insRoutePrpsFeeVO.getFeeAmt(),actAmt,10)*100);
											}
                                            view.addObject("insRouteInfo", "由于该报价方案客户保证金计算基数与资管路由不一致，系统已重新推算比例值");
										}
									}
								}
							}
						}
					}
				}
				if(mediationFeeAmtSum != 0 && !fee76){
					PrjQuatPrpsCfgDVO prjQuatPrpsCfgDVO = new PrjQuatPrpsCfgDVO();
					prjQuatPrpsCfgDVO.setPrpsCfgId(list.get(0).getPrpsCfgId());
					prjQuatPrpsCfgDVO.setFeeTypCd(PrjQuatPrpsFeeConstant.FEE_TYP_CD_76);
					prjQuatPrpsCfgDVO.setFeeTypCdNm("调节费");
					prjQuatPrpsCfgDVO.setIsAllowChg(BaseConstant.IS_YESNO_YES);
					prjQuatPrpsCfgDVO.setIsAllowChgNm("是");
					prjQuatPrpsCfgDVO.setIsSysDef(BaseConstant.IS_YESNO_NO);
					prjQuatPrpsCfgDVO.setIsSysDefNm("否");
					prjQuatPrpsCfgDVO.setFixedAmt(mediationFeeAmtSum);
					if(PrjBscInfoConstant.PRJ_TYP_CD_CDDYWUL.equals(prjTypCd) || PrjBscInfoConstant.PRJ_TYP_CD_ESCJYD.equals(prjTypCd) || PrjBscInfoConstant.PRJ_TYP_CD_OWNJYD.equals(prjTypCd)){
						prjQuatPrpsCfgDVO.setCntWayCd(PrjQuatPrpsConstant.CODE_PRJ_QUAT_CNT_WAY_CONT);
						prjQuatPrpsCfgDVO.setCntWayCdNm("计入合同额");
						prjQuatPrpsCfgDVO.setIsAllowChg(BaseConstant.IS_YESNO_NO);
					}else{
						prjQuatPrpsCfgDVO.setCntWayCd(PrjQuatPrpsConstant.CODE_PRJ_QUAT_CNT_WAY_OTH);
						prjQuatPrpsCfgDVO.setCntWayCdNm("其他费用");
					}
					prjQuatPrpsCfgDVO.setIsFixedAmt(BaseConstant.IS_YESNO_YES);
					prjQuatPrpsCfgDVO.setIsFixedAmtNm("是");
					list.add(prjQuatPrpsCfgDVO);
				}
			}
		}
		PrjPrdBscInfoQueryCondition prdQc = new PrjPrdBscInfoQueryCondition();
		if(StringUtils.isNotBlank(prjId)){
			prdQc.setPrjId(Long.valueOf(prjId));
			List<PrjPrdBscInfoVO> prdList=	this.prjPrdBscInfoService.searchList(prdQc);
			if(CollectionUtils.isNotEmpty(prdList)){
				view.addObject("prdList",JSON.toJSONString(prdList));
				for (PrjPrdBscInfoVO prjPrdBscInfoVO : prdList) {
					//资管项目、报价方案配置留购价不可变更、留购价与项目产品留购价不一致提示校验信息
					if(bscInfoVO.getIsInsBiz().equals(BaseConstant.IS_YESNO_YES) && isAllowChg == BaseConstant.IS_YESNO_NO && !prjPrdBscInfoVO.getRsrvPc().equals(quatRsrvPc)){
						throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"该资方要求留购价为固定"+ DecimalUtils.convertFenToYuan(new Double(quatRsrvPc).longValue()) + "元/台，请在项目产品信息中修改！");
					}
					if(CapitalConstant.CODE_PAYEE_TYP_CD_1.equals(prjPrdBscInfoVO.getReceiveTypeCd())){
						isDealer = true;
					}
					splId = prjPrdBscInfoVO.getSplId();
					prdNum +=prjPrdBscInfoVO.getPrdQty();
					/**
					 * 江西金租 租赁物总价值 取值要区分 （主要是二手车交易贷 和 车抵贷线下）
					 */
					if(StringUtils.isNotEmpty(prjTypCd) && StringUtils.isNotEmpty(bscInfoVO.getInsCode())
							&& StringUtils.isNotEmpty(bscInfoVO.getBuOrgCd()) && PrjBscInfoConstant.CODE_BU_ORG_CD_ZK.equals(bscInfoVO.getBuOrgCd())
							&& (PrjBscInfoConstant.PRJ_INS_CODE_JXFL.equals(bscInfoVO.getInsCode())
							|| PrjBscInfoConstant.PRJ_INS_CODE_XYFL.equals(bscInfoVO.getInsCode())
							|| PrjBscInfoConstant.PRJ_INS_CODE_TYFL.equals(bscInfoVO.getInsCode())
							|| PrjBscInfoConstant.PRJ_INS_CODE_HRBANK.equals(bscInfoVO.getInsCode())
							|| PrjBscInfoConstant.PRJ_INS_CODE_WEBANK.equals(bscInfoVO.getInsCode())
							|| PrjBscInfoConstant.PRJ_INS_CODE_SYFL.equals(bscInfoVO.getInsCode())
							|| PrjBscInfoConstant.PRJ_INS_CODE_CCBANK.equals(bscInfoVO.getInsCode())
							|| PrjBscInfoConstant.PRJ_INS_CODE_CCBANKTB.equals(bscInfoVO.getInsCode())
							|| PrjBscInfoConstant.PRJ_INS_CODE_JXYMBANK.equals(bscInfoVO.getInsCode())
							|| PrjBscInfoConstant.PRJ_INS_CODE_TIANJINBANK.equals(bscInfoVO.getInsCode())
							|| PrjBscInfoConstant.PRJ_INS_CODE_YLBANK.equals(bscInfoVO.getInsCode())
							|| PrjBscInfoConstant.PRJ_INS_CODE_SSFL.equals(bscInfoVO.getInsCode())
					)){
						/**
						 * 车抵贷线下 取客户融资额
						 */
						if(prjTypCd.equals(PrjBscInfoConstant.PRJ_TYP_CD_CDDYWUL)){
							if(PrjBscInfoConstant.PRJ_INS_CODE_JXFL.equals(bscInfoVO.getInsCode())
									|| PrjBscInfoConstant.PRJ_INS_CODE_XYFL.equals(bscInfoVO.getInsCode())
									|| PrjBscInfoConstant.PRJ_INS_CODE_SYFL.equals(bscInfoVO.getInsCode())
							){
								if(null != prjPrdBscInfoVO.getCustFina()){
									totalPrdAmt += DecimalUtils.mul(prjPrdBscInfoVO.getCustFina(), prjPrdBscInfoVO.getPrdQty());
								}
							}else{
								if(null != prjPrdBscInfoVO.getVehVal()){
									totalPrdAmt += DecimalUtils.mul(prjPrdBscInfoVO.getVehVal(), prjPrdBscInfoVO.getPrdQty());
								}
							}
						}
						/**
						 * 二手车交易贷 取 车辆评估价
						 */
						if(prjTypCd.equals(PrjBscInfoConstant.PRJ_TYP_CD_ESCJYD) || prjTypCd.equals(PrjBscInfoConstant.PRJ_TYP_CD_OWNJYD)){
							if(null != prjPrdBscInfoVO.getVehVal()){
								totalPrdAmt += DecimalUtils.mul(prjPrdBscInfoVO.getVehVal(), prjPrdBscInfoVO.getPrdQty());
							}
						}
						/**
						 * 城配业务 和 传统业务 取 产品指导价
						 */
						if(prjTypCd.equals(PrjBscInfoConstant.PRJ_TYP_CD_CPYW) || prjTypCd.equals(PrjBscInfoConstant.PRJ_TYP_CD_CTYW) ){
							totalPrdAmt += DecimalUtils.mul(prjPrdBscInfoVO.getGuidePc(), prjPrdBscInfoVO.getPrdQty());
						}
					}else{
						totalPrdAmt += DecimalUtils.mul(prjPrdBscInfoVO.getGuidePc(), prjPrdBscInfoVO.getPrdQty());
					}
					if(null!=prjPrdBscInfoVO.getRsrvPc()){
						totalRsrvPc +=DecimalUtils.mul(prjPrdBscInfoVO.getRsrvPc(), prjPrdBscInfoVO.getPrdQty());
					}
					//车辆参考价是否可编辑标志,合同额 = 设备款合计(车辆数*参考价)
					if(BaseConstant.IS_YESNO_YES_STR.equals(guidePcEditFlag)){
						totalPrdAmtReplace += DecimalUtils.mul(prjPrdBscInfoVO.getGuidePc(), prjPrdBscInfoVO.getPrdQty());
					}
				}
			}
		}
		CalQuatPrpsVO calQuatPrpsVO = null;
		//厂商报价器信息
        if(bscInfoVO.getBuOrgCd().equals(PrjBscInfoConstant.CODE_BU_ORG_CD_ZK) && null!=bscInfoVO.getIsSplMfr()&&bscInfoVO.getIsSplMfr()== BaseConstant.IS_YESNO_YES&&null!=bscInfoVO.getCalId()){
            calQuatPrpsVO = this.calQuatPrpsService.selectCalQuatProsAndDetailById(bscInfoVO.getCalId());
            view.addObject("calQuatPrps",  JSON.toJSONString(calQuatPrpsVO));//配置方案信息
        }

        //车辆参考价是否可编辑标志,合同额 = 设备款合计(车辆数*参考价)
        if(BaseConstant.IS_YESNO_YES_STR.equals(guidePcEditFlag)){
			totalPrdAmt = totalPrdAmtReplace;
		}

		BigDecimal bd = new BigDecimal(totalPrdAmt);
		String totalPrdAmtStr = bd.toPlainString();
		if(prjTypCd.equals(PrjBscInfoConstant.PRJ_TYP_CD_CDDYWYQ)){
			totalPrdAmtStr = String.valueOf(totalPrdAmt);
		}
		Double cntAmt = Double.valueOf(totalPrdAmtStr) + mediationFeeAmtSum;
		BigDecimal rsrvPc = new BigDecimal(DecimalUtils.convertFenToYuan(new Double(totalRsrvPc).longValue()));
		String totalRsrvPcStr = rsrvPc.toPlainString();
		//根据id查询修改数据
		if(StringUtils.isNotBlank(id)){
			//查询已经保存的报价方案
			PrjQuatPrpsVO prjQuatPrps = this.prjQuatPrpsService.selectById(Long.valueOf(id));
			ListPageVO<PrjQuatPrpsPaySchVO> payListPage = new ListPageVO<PrjQuatPrpsPaySchVO>(prjQuatPrps.getPrjQuatPrpsPaySchList(),prjQuatPrps.getPrjQuatPrpsPaySchList().size());
			prjQuatPrps.setPrjQuatPrpsPaySchPage(payListPage);
			ListPageVO<PrjQuatPrpsFeeVO> detailListPage = new ListPageVO<PrjQuatPrpsFeeVO>(prjQuatPrps.getPrjQuatPrpsFeelist(),prjQuatPrps.getPrjQuatPrpsFeelist().size());
			if(CollectionUtils.isNotEmpty(prjQuatPrps.getPrjQuatPrpsFeelist())){
				for (PrjQuatPrpsFeeVO fee : prjQuatPrps.getPrjQuatPrpsFeelist()) {
					if(fee.getFeeTypCd().equals(PrjQuatPrpsFeeConstant.FEE_TYP_CD_54)){
						if (null != fee.getFeePct()) {
							mfrDiscountRate = fee.getFeePct();
						}
					}
				}
			}
			// 如果开关打开、是重卡传统/城配项目，如果小贷额度不为空，单位转换为元
			if (prjQuatPrps.getSmallLoanAmt() != null && prjQuatPrps.getSmallLoanAmt()>0){
				prjQuatPrps.setSmallLoanAmt(DecimalUtils.convertFenToYuan(prjQuatPrps.getSmallLoanAmt().longValue()));
			}
			prjQuatPrps.setPrjQuatPrpsFeePage(detailListPage);
			view.addObject("detailListPage", JSON.toJSONString(detailListPage));
			view.addObject("payListPage", JSON.toJSONString(payListPage));
			view.addObject("prjQuatPrps", JSON.toJSONString(prjQuatPrps));
            view.addObject("cstIrr", prjQuatPrps.getCstIrr());
			prpsTypCd = prjQuatPrps.getPrpsTypCd();
		}
		view.addObject("id", id);
		//租赁期数单位
		List<KeyValueVO> lsPdUntCdList = this.prjQuatPrpsCfgMService.searchLsPdUntCdList();
		view.addObject("lsPdUntCdList", lsPdUntCdList);
		//支付方式
		List<KeyValueVO> payWayCdList = this.prjBscInfoService.getKeyValueList(DictionaryConstant.CODE_PRJ_QUAT_PAY_WAY_CD,CurrentThreadContext.getCurrentSysCd(),bscInfoVO.getCstMgrOrgCd());
		/*List<KeyValueVO> payWayCdList = this.prjQuatPrpsCfgMService.searchPayWayCdList();*/
		view.addObject("payWayCdList", payWayCdList);
		//保证金处理方式
		List<KeyValueVO> dpstHdlWayCdList = this.prjQuatPrpsCfgMService.searchDpstHdlWayCdList();
		view.addObject("dpstHdlWayCdList", dpstHdlWayCdList);//客户保证金处理方式
		// 渠道保证金处理方式
		List<KeyValueVO> chlDpstPwayCdList = sysDictionaryApiService.getKvList(DictionaryConstant.CHL_DPST_PWAY_GRP_CD, CurrentThreadContext.getFlServiceSysCd(), CurrentThreadContext.getCurrentOrgCd());
		view.addObject("chlDpstPwayCdList", chlDpstPwayCdList);
		//租赁期满处理方式
		List<KeyValueVO> expHdlWayCdList = this.prjQuatPrpsCfgMService.searchExpHdlWayCdList();
		view.addObject("expHdlWayCdList", expHdlWayCdList);
		//一城一策
		List<KeyValueVO> oneCityOnePolicyTypeCdList = this.prjQuatPrpsCfgMService.searchOneCityOnePolicyTypeCdList(bscInfoVO.getCstMgrOrgCd());
		view.addObject("oneCityOnePolicyTypeCdList", oneCityOnePolicyTypeCdList);
		//不还款处理方式
		List<KeyValueVO> noPayWayCdList = this.prjBscInfoService.searchNoPayWayCdList();
		view.addObject("noPayWayCdList", noPayWayCdList);
		//费用类型
		JSONArray feeTypCdListJSON = this.prjQuatPrpsCfgMService.searchFeeTypCdList();
		view.addObject("feeTypCdListJSON", feeTypCdListJSON);
		//费用计算基数
		List<KeyValueVO> calBaseCdList = this.prjQuatPrpsCfgMService.searchCalBaseCdList();
		view.addObject("calBaseCdListJSON", JSON.toJSONString(calBaseCdList));
		List<KeyValueVO> yesNoCdList = this.prjQuatPrpsCfgMService.searchYesOrNoCdList();
		view.addObject("yesNoCdList",yesNoCdList);
		view.addObject("yesOrNoCdListJSON",JSON.toJSONString(yesNoCdList) );
		//费用计入方式
		List<KeyValueVO> cntWayCdList = this.prjQuatPrpsCfgMService.searchCntWayCdList();
		//计算方式
		List<KeyValueVO> lsCalWayCdList = this.prjBscInfoService.searchLsCalWayCdList();
		//商业险金额
		List<KeyValueVO> businessInsCdList = this.prjBscInfoService.searchBusinessInsCdList();
		view.addObject("businessInsCdList",businessInsCdList);
		//租赁年利率计算方式
		List<KeyValueVO> intRateWayCdList = this.prjBscInfoService.searchIntRateWayCdList();
		//拆分比例
		/*List<KeyValueVO> prjQuatSplitPctList = this.prjBscInfoService.getPrjQuatSplitPctList();*/
		List<KeyValueVO> prjQuatSplitPctList = this.prjBscInfoService.getKeyValueList(DictionaryConstant.CODE_QUAT_SPLIT_CD,CurrentThreadContext.getCurrentSysCd(),bscInfoVO.getCstMgrOrgCd());
		//特殊业务列表
		if(isDealer){
			Map<String,String> specialBusiness = this.iSplPropInfoApiService.getSpePowMapBySplId(splId,CurrentThreadContext.getCurrentSysCd(),CurrentThreadContext.getCurrentOrgCd());
			logger.info("根据经销商id查询特殊业务列表信息specialBusiness:{}", JSON.toJSONString(specialBusiness));
			if(bscInfoVO.getBuOrgCd().equals(PrjBscInfoConstant.CODE_BU_ORG_CD_ZK) && CollectionUtils.isMapNotEmpty(specialBusiness)){
				//isShowSpecialBusiness = true;
				Iterator<Map.Entry<String, String>> it = specialBusiness.entrySet().iterator();
				while(it.hasNext()){
					Map.Entry<String, String> entry=it.next();
					String key=entry.getKey();
					if(PrjQuatPrpsConstant.SPECIAL_BUSINESS_TYPE_3.equals(key)){
						isSupportLowRateForDealers = true;
						//根据机构编码查询是否支持低息业务
						if(bscInfoVO.getInsCode() != null){
							SysDictionaryDTO sysDictionaryDTO = sysDictionaryApiService.getEntityByPriKey("11000", "0000", DictionaryConstant.CODE_IS_LOWRATE_INS_CD, bscInfoVO.getInsCode());
							if(sysDictionaryDTO == null){
								it.remove();
							}
						}else{
							//我司不支持低息业务
							it.remove();
						}
					}else if(PrjQuatPrpsConstant.SPECIAL_BUSINESS_TYPE_9.equals(key) || PrjQuatPrpsConstant.SPECIAL_BUSINESS_TYPE_7.equals(key) || PrjQuatPrpsConstant.SPECIAL_BUSINESS_TYPE_8.equals(key)){
						it.remove();
					}
				}
			}
			view.addObject("specialBusiness",specialBusiness);
		}
		//view.addObject("isShowSpecialBusiness",isShowSpecialBusiness);
		view.addObject("isSupportLowRateForDealers",isSupportLowRateForDealers);
		view.addObject("isDealer",isDealer);

		//业务线字典List
		List<KeyValueVO> bussinessLineDicList = sysDictionaryApiService.getKvList("REF0048","11000","0000");
		//机构信息List
		List<FriBaseInfoVO> friBaseInfoVOList = this.friBaseInfoService.searchList(new FriBaseInfoQueryCondition());
		//根据金融机构业务线,设置金融机构名称展示字段值
		FundRasInsNmChangeUtil.insNmShowAddBussinessLineDic(friBaseInfoVOList,bussinessLineDicList);
		view.addObject("friBaseList", friBaseInfoVOList);

		/**
		 * 新能源 浦发 拆分比例 默认设置0.0  0 不设置会影响页面测算
		 */
		if(StringUtils.isNotEmpty(bscInfoVO.getInsCode()) && bscInfoVO.getInsCode().equals(PrjBscInfoConstant.PRJ_INS_CODE_SPD)
			&& bscInfoVO.getBuOrgCd().equals(PrjBscInfoConstant.CODE_BU_ORG_CD_XNY)){
			KeyValueVO prjQuatSpltPct = new KeyValueVO();
			prjQuatSpltPct.setKey("0.0");
			prjQuatSpltPct.setValue("0");
			prjQuatSplitPctList.add(prjQuatSpltPct);
		}
		List<SysDictionaryDTO>  pctList = new ArrayList<SysDictionaryDTO>();
		pctList = this.sysDictionaryApiService.searchGroup(CurrentThreadContext.getCurrentSysCd(), bscInfoVO.getBuOrgCd(), DictionaryConstant.CODE_QUAT_SPLIT_CD);
		if(CollectionUtils.isNotEmpty(pctList)){
			for (SysDictionaryDTO sysDictionaryDTO : pctList) {
				if(StringUtils.isNotBlank(sysDictionaryDTO.getCodeDesc())&&sysDictionaryDTO.getCodeDesc().equals(String.valueOf((BaseConstant.IS_YESNO_YES)))){
					defSplitPct = Double.valueOf(sysDictionaryDTO.getCode());
				}
			}
		}
		if(null!= prjTypCd && prjTypCd.equals(PrjBscInfoConstant.PRJ_TYP_CD_ESC)){
			defSplitPct = 0d;
		}
		if(StringUtils.isNotEmpty(bscInfoVO.getInsCode()) && bscInfoVO.getInsCode().equals(PrjBscInfoConstant.PRJ_INS_CODE_SPD)){
			defSplitPct = 0d;
		}
		//前期租金比例
		List<Integer>  ycPdList = new ArrayList<Integer>();//优车允许填写的期次
		List<KeyValueVO> prjPreRntPctList = this.prjBscInfoService.getKeyValueList(DictionaryConstant.CODE__PRJ_PRE_RNT_PCT_CD,CurrentThreadContext.getCurrentSysCd(),bscInfoVO.getCstMgrOrgCd());
		/*List<KeyValueVO> prjPreRntPctList = this.prjBscInfoService.getPrjPreRntPctList();*/
		if(CollectionUtils.isNotEmpty(prjPreRntPctList)){
			for (KeyValueVO keyValueVO : prjPreRntPctList) {
				String[] valueStr = keyValueVO.getKey().split("-");
				int pd = Integer.valueOf(valueStr[0]);
				ycPdList.add(pd);
			}
		}
		//是否包牌下拉列表
		List<KeyValueVO> isBpList = new ArrayList<KeyValueVO>();
		if(StringUtils.isNotEmpty(bscInfoVO.getBuOrgCd())) {
			 isBpList = this.sysDictionaryApiService.getKvList(DictionaryConstant.CODE_IS_BP_LIST_CD,CurrentThreadContext.getCurrentSysCd() ,bscInfoVO.getBuOrgCd());
		}else{
			 isBpList = this.sysDictionaryApiService.getKvList(DictionaryConstant.CODE_IS_BP_LIST_CD,CurrentThreadContext.getCurrentSysCd() , CurrentThreadContext.getCurrentOrgCd());
		}
		/*boolean isBpFlag = true;
		try {
			isBpFlag = prjPlcyIndexApiService.searchBpPlcyOpen(Long.valueOf(prjId));
		}catch (BaseException ex) {
			isBpFlag = false;
			BaseLogUtils.info(logger, "removeById", "查询方案判定规则异常"+ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}catch (Exception ex) {
			isBpFlag = false;
			BaseLogUtils.error(logger, "removeById", "查询方案判定规则异常"+ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}*/
		if((PrjBscInfoConstant.CODE_BU_ORG_CD_ZK.equals(bscInfoVO.getBuOrgCd())&&(PrjBscInfoConstant.PRJ_TYP_CD_ESCJYD.equals(prjTypCd) || PrjBscInfoConstant.PRJ_TYP_CD_CDDYWUL.equals(prjTypCd) || PrjBscInfoConstant.PRJ_TYP_CD_OWNJYD.equals(prjTypCd)))
				||(PrjBscInfoConstant.CODE_BU_ORG_CD_YC.equals(bscInfoVO.getBuOrgCd())&&(PrjBscInfoConstant.PRJ_TYP_CD_ESCJYD.equals(prjTypCd)
                 || PrjBscInfoConstant.PRJ_TYP_CD_CDDYWUL.equals(prjTypCd)))){
			isShowBp = BaseConstant.IS_YESNO_NO;
		}
		/*if(isBpFlag){
			isShowBp = BaseConstant.IS_YESNO_YES;
		}*/
		Map<String,String>  scaleNumMap  =  this.prjQuatPrpsService.getDecimalDigitsByBuOrgCodeNew(bscInfoVO.getCstMgrOrgCd());
		//厂商业务方案政策列表
		List<KeyValueVO> policyTypCdList = this.sysDictionaryApiService.getKvList(DictionaryConstant.CODE_QUAT_POLICY_TYP_CD,CurrentThreadContext.getCurrentSysCd() , bscInfoVO.getCstMgrOrgCd());
		view.addObject("isSplMfr", bscInfoVO.getIsSplMfr());
		view.addObject("isBpList", isBpList);
		view.addObject("isShowBp", isShowBp);
		view.addObject("cntWayCdListJSON", JSON.toJSONString(cntWayCdList));
		view.addObject("prjId", prjId);
		view.addObject("quatPrps", quatPrps);//配置方案信息
		view.addObject("quatPrpsJson", quatPrps==null?"": JSON.toJSONString(quatPrps));//配置方案信息
		view.addObject("PrjQuatPrpsCfgDetailList", list);//配置明细信息
		view.addObject("lsPdUntCdList", lsPdUntCdList);//租赁期数单位
		view.addObject("payWayCdList", payWayCdList);//支付方式
		view.addObject("lsCalWayCdList", lsCalWayCdList);//计算方式
		view.addObject("calBaseCdList", calBaseCdList);//费用计算基数
		view.addObject("cntWayCdList", cntWayCdList);///费用计入方式
		view.addObject("intRateWayCdList", intRateWayCdList);//租赁年利率计算方式
		view.addObject("expHdlWayCdList", expHdlWayCdList);//租赁期满处理方式
		view.addObject("prdNum", prdNum);//产品数量
		view.addObject("totalPrdAmt",totalPrdAmtStr);
		view.addObject("cntAmt",cntAmt);
		/**
		 * 资管机构 兴邦留购价设置为0
		 */
		if(StringUtils.isNotEmpty(bscInfoVO.getInsCode()) && bscInfoVO.getInsCode().equals(PrjBscInfoConstant.PRJ_INS_CODE_XBFL)){
			totalRsrvPcStr = "0";
		}
		Long preInsId = null;
		if(bscInfoVO.getPreResId() != null){
			PreRouteInsResVO preRouteInsResVO = this.preRouteInsResService.selectById(bscInfoVO.getPreResId());
			preInsId = preRouteInsResVO.getInsId();
		}
		view.addObject("preInsId",preInsId);//预筛选机构
		view.addObject("totalRsrvPcStr",totalRsrvPcStr);//留购价总金额
		view.addObject("detailFlag",detailFlag);
		view.addObject("prpsCfgId", prpsCfgId);
		view.addObject("scaleNumMap", scaleNumMap.isEmpty()==true?"":JSON.toJSONString(scaleNumMap));
		view.addObject("prpsTypCd", prpsTypCd);
		view.addObject("prjQuatSplitPctList", prjQuatSplitPctList);
		view.addObject("isFlow", isFlow);
		view.addObject("defSplitPct", defSplitPct);
		view.addObject("buOrgCd", bscInfoVO.getBuOrgCd());
		view.addObject("mfrDiscountRate", mfrDiscountRate);
		view.addObject("prjTypCd", prjTypCd);
		view.addObject("prjPreRntPctList", prjPreRntPctList);
		view.addObject("ycPdList", ycPdList);
		view.addObject("insCode",null==bscInfoVO.getInsCode()?"":bscInfoVO.getInsCode());
		view.addObject("isInsBiz",bscInfoVO.getIsInsBiz());
		view.addObject("policyTypCdList",policyTypCdList);
        view.addObject("calId",null==bscInfoVO.getCalId()?"":bscInfoVO.getCalId());
        view.addObject("compensatoryType",bscInfoVO.getCompensatoryType()==null?"0":bscInfoVO.getCompensatoryType());
		logger.info("跳转到添加页面,返回方案配置信息,项目id={}",prjId);
		return view;
	}

	/**
	 * 初始化列表
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/initList.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object initList(HttpServletRequest request, HttpServletResponse response) {
		String currentPage = request.getParameter("page");
		String pageSize = request.getParameter("pagesize");
		String prjId = request.getParameter("prjId");
		String quatTypeCd = request.getParameter("quatTypCd");//报价方案类型
		Pager page = new Pager();
		if (StringUtils.isNotEmpty(currentPage)) {
			page.setCurrentPage(Integer.parseInt(currentPage));
		}

		if (StringUtils.isNotEmpty(currentPage)) {
			page.setEveryPage(Integer.parseInt(pageSize));
		}

		PrjQuatPrpsQueryCondition qc = new PrjQuatPrpsQueryCondition();
		if (StringUtils.isNotEmpty(prjId)) {
			qc.setPrjId(Long.valueOf(prjId));
		}
		if(StringUtils.isNotBlank(quatTypeCd)){
			qc.setPrpsTypCd(quatTypeCd);
		}
		page.setCondition(qc);
		Pager pager = this.prjQuatPrpsService.searchListPage(page);
		
		List<PrjQuatPrpsVO> list = (List<PrjQuatPrpsVO>) pager.getResultList();
		ListPageVO<PrjQuatPrpsVO> listPage = new ListPageVO<PrjQuatPrpsVO>(list, pager.getTotalCount());
		logger.info("查询报价方案列表page:{}", JSON.toJSONString(page));
		return listPage;
	}

	/**
	 * 删除数据
	 */
	@RequestMapping(value = "/removeByIds.do", method = {RequestMethod.POST })
	@ResponseBody
	public DataResultVO removeById(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String ids = request.getParameter("ids");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_DELETE_SUCC);
		if(StringUtils.isEmpty(ids)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
			return result;
		}
		List<Long> idList = new ArrayList<Long>();
		JSONArray idsArray = JSONArray.fromObject(ids);
		for (Object object : idsArray) {
			idList.add(Long.valueOf(object.toString()));
		}
		try {
			this.prjQuatPrpsService.removeByIds(idList);
			logger.info("批量删除报价方案removeById:{}", ids);
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			logger.error("批量删除报价方案失败removeById:{}，msg:{}", ids,ex.getMessage());
		}catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			logger.error("批量删除报价方案失败removeById:{},msg:{}", ids,ex.getMessage());
		}
		result.setSuccess(BaseConstant.IS_YESNO_YES);
		return result;
	}
	/**
	 * 根据选择的类型查询年利率信息
	 * 
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/getQuatPrpsCfgAiByQuatId.do", method = { RequestMethod.POST})
	@ResponseBody
	public Object getQuatPrpsCfgAiByQuatId(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String quatId = request.getParameter("quatId");//方案ID
		String lsPd = request.getParameter("lsPd");//开始年利率
		String lsPdUntCd = request.getParameter("lsPdUntCd");//租赁期数单位
		Pager page = new  Pager();
		PrjQuatPrpsCfgAiQueryCondition qc = new PrjQuatPrpsCfgAiQueryCondition();
		if(StringUtils.isNotBlank(quatId)){
			qc.setPrpsCfgId(Long.valueOf(quatId));
		}
		if(StringUtils.isNotBlank(lsPd)){
			qc.setLsPd(Long.valueOf(lsPd));
		}
		if(StringUtils.isNotBlank(lsPdUntCd)){
			qc.setLsPdUntCd(lsPdUntCd);
		}
		page.setCondition(qc);
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_OPERATE_SUCC);
		if(StringUtils.isEmpty(quatId)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
			logger.info("获取报价方案配置信息失败，id为空");
			return result;
		}
		
		try {
			Pager pager = this.prjQuatPrpsCfgAiService.searchListPage(page);
			PrjQuatPrpsCfgAiVO vo = null;
			List<PrjQuatPrpsCfgAiVO>list =(List<PrjQuatPrpsCfgAiVO>)pager.getResultList();
			if(CollectionUtils.isNotEmpty(list)){
				vo = list.get(0);
			}
			result.setData(vo);
			logger.info("获取报价方案配置信息quatId:{}",quatId);
		}catch(BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			logger.error("获取报价方案配置信息失败quatId:{}，msg{}",quatId,ex.getMessage());
		}catch(Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			logger.error("获取报价方案配置信息失败quatId:{},msg:{}",quatId,ex.getMessage());
		}
		return result;
	}
	
	/**
	 * 工商银行
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/prjQuatFeeConsAmt.do", method = { RequestMethod.POST})
	@ResponseBody
	public Object prjQuatFeeConsAmt(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String quatId = request.getParameter("quatId");//方案ID
		String lsPd = request.getParameter("lsPd");//开始年利率
		String prjId = request.getParameter("prjId");//项目ID
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_OPERATE_SUCC);
		if(StringUtils.isEmpty(quatId)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
			logger.info("获取资费比例失败,方案id为空");
			return result;
		}
		
		try {
			//咨询费比例
			double consultPct = 0d;
			   Integer isNew = null;//是否是新车
			  //最新规则
                   PrjPrdBscInfoQueryCondition prdQc = new PrjPrdBscInfoQueryCondition();
                   prdQc.setPrjId(Long.valueOf(prjId));
                   List<PrjPrdBscInfoVO> prjPrdBscList = this.prjPrdBscInfoService.searchList(prdQc);
                   if(CollectionUtils.isNotEmpty(prjPrdBscList)){
                        PrjPrdBscInfoVO      prjPrdBscInfoDTO = prjPrdBscList.get(0);
                        if(null!=prjPrdBscInfoDTO.getIsNew()){
                             isNew = prjPrdBscInfoDTO.getIsNew();
                        }
                   }
                   if(null==isNew){
                          throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "请维护项目产品的是否新车信息！");
                   }
                   PrjQuatPrpsRebQueryCondition qc = new PrjQuatPrpsRebQueryCondition();
                   qc.setPrpsCfgId(Long.valueOf(quatId));
                   qc.setIsNew(isNew);
                   qc.setLsPd(Long.valueOf(lsPd));
                   qc.setPctTypCd(PrjQuatPrpsConstant.CODE_QUAT_CONS_RATE_CD);
                   //查询供应商政策比例
                   List<PrjQuatPrpsRebVO> rebList = this.prjQuatPrpsRebService.searchList(qc);
                   List<PrjQuatPrpsRebVO> lsRebList = null;
                   List<PrjQuatPrpsRebVO> newLsRebList = null;
                   List<PrjQuatPrpsRebVO> nullLsRebList = null;
                   if(CollectionUtils.isNotEmpty(rebList)){
                	   consultPct =rebList.get(0).getLsRebPct();
                   }
                   if(CollectionUtils.isEmpty(rebList)||rebList.size()==0){
                	   //根据期数查询
                	   PrjQuatPrpsRebQueryCondition lsQc = new PrjQuatPrpsRebQueryCondition();
                	   lsQc.setPrpsCfgId(Long.valueOf(quatId));
                	   lsQc.setLsPd(Long.valueOf(lsPd));
                	   lsQc.setPctTypCd(PrjQuatPrpsConstant.CODE_QUAT_CONS_RATE_CD);
                	    lsRebList = this.prjQuatPrpsRebService.searchList(lsQc);
                	   if(CollectionUtils.isNotEmpty(lsRebList)){
                		   consultPct =lsRebList.get(0).getLsRebPct();
                	   }else{
                		   lsRebList = new ArrayList<PrjQuatPrpsRebVO>();
                	   }
                   }
                   if((CollectionUtils.isEmpty(rebList)||rebList.size()==0)&&(CollectionUtils.isEmpty(lsRebList)||lsRebList.size()==0)){
                	   //根据是否新车查询
                	 //根据期数查询
                	   PrjQuatPrpsRebQueryCondition newlsQc = new PrjQuatPrpsRebQueryCondition();
                	   newlsQc.setPrpsCfgId(Long.valueOf(quatId));
                	   newlsQc.setIsNew(isNew);
                	   newlsQc.setPctTypCd(PrjQuatPrpsConstant.CODE_QUAT_CONS_RATE_CD);
                	   newLsRebList = this.prjQuatPrpsRebService.searchList(newlsQc);
                	   if(CollectionUtils.isNotEmpty(newLsRebList)){
                		   consultPct =newLsRebList.get(0).getLsRebPct();
                	   }else{
                		   newLsRebList = new ArrayList<PrjQuatPrpsRebVO>();
                	   }
                   }
                   //查询期数、是否新车为空的数据
                   if((CollectionUtils.isEmpty(rebList)||rebList.size()==0)&&(CollectionUtils.isEmpty(lsRebList)||lsRebList.size()==0)&&(CollectionUtils.isEmpty(newLsRebList)||newLsRebList.size()==0)){
                	   PrjQuatPrpsRebQueryCondition rebQc = new PrjQuatPrpsRebQueryCondition();
                	   rebQc.setPrpsCfgId(Long.valueOf(quatId));
                	   rebQc.setPctTypCd(PrjQuatPrpsConstant.CODE_QUAT_CONS_RATE_CD);
                	   nullLsRebList = this.prjQuatPrpsRebService.searchList(rebQc);
                	   if(CollectionUtils.isNotEmpty(nullLsRebList)){
                		   consultPct =nullLsRebList.get(0).getLsRebPct();
                	   }else{
                		   nullLsRebList = new ArrayList<PrjQuatPrpsRebVO>();
                	   }
                   }
			logger.info("获取资费比例prjId:{};quatId:{}",prjId,quatId);
            result.setData(consultPct);
		}catch(BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			logger.error("获取资费比例失败quatId:{},msg:{}",quatId,ex.getMessage());
		}catch(Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			logger.error("获取资费比例失败msg:{}",ex.getMessage());
		}
		return result;
	}
	/**
	 * 获取项目方案列表
	 * 
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/getPrjQuatDetailById.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object getPrjQuatDetailById(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String prjId = request.getParameter("prjId");
		String id = request.getParameter("id");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_OPERATE_SUCC);
		if(StringUtils.isEmpty(id)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
			logger.info("获取项目方案列表失败，id为空");
			return result;
		}
			//根据id查询修改数据
		//查询已经保存的报价方案
		PrjQuatPrpsVO prjQuatPrps = this.prjQuatPrpsService.selectById(Long.valueOf(id));
		ListPageVO<PrjQuatPrpsFeeVO> detailListPage = new ListPageVO<PrjQuatPrpsFeeVO>(prjQuatPrps.getPrjQuatPrpsFeelist(),prjQuatPrps.getPrjQuatPrpsFeelist().size());
		prjQuatPrps.setPrjQuatPrpsFeePage(detailListPage);
		logger.info("获取项目方案列表id:{},prjId:{}",id,prjId);
		return detailListPage;
	}
	/**
	 * 获取项目方案列表
	 * 
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/getPrjQuatPayById.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object getPrjQuatPayById(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String id = request.getParameter("id");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_OPERATE_SUCC);
		if(StringUtils.isEmpty(id)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
			logger.info("获取项目方案失败，id为空");
			return result;
		}
			//根据id查询修改数据
		//查询已经保存的报价方案
		PrjQuatPrpsVO prjQuatPrps = this.prjQuatPrpsService.selectById(Long.valueOf(id));
		ListPageVO<PrjQuatPrpsPaySchVO> payListPage = new ListPageVO<PrjQuatPrpsPaySchVO>(prjQuatPrps.getPrjQuatPrpsPaySchList(),prjQuatPrps.getPrjQuatPrpsPaySchList().size());
		prjQuatPrps.setPrjQuatPrpsPaySchPage(payListPage);
		logger.info("获取项目方案id;{}",id);
		return payListPage;
	}
	/**
	 * 得到一条记录
	 * 
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/getById.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object getById(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String id = request.getParameter("id");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_OPERATE_SUCC);
		if(StringUtils.isEmpty(id)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
			logger.info("获取项目报价方案失败，参数id为空");
			return result;
		}
		
		try {
			PrjQuatPrpsVO vo = this.prjQuatPrpsService.selectById(Long.valueOf(id));
			if(null == vo){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo(SysLogConstant.LOG_CMM_QUERY_DATA_IS_EMPTY);
				logger.info("获取项目报价方案失败，参数id为空");
			}
			Long quatCfgId = vo.getPrpsCfgId();
			PrjQuatPrpsCfgMVO cfg = null;
			if(StringUtils.isNotEmpty(quatCfgId)){
				 cfg = 	this.prjQuatPrpsCfgMService.selectById(quatCfgId);
			}
			vo.setPrjQuatPrpsCfgM(cfg);
			result.setData(vo);
			logger.info("获取项目报价方案result:{}", JSON.toJSONString(vo));
		}catch(BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			logger.error("获取项目报价方案失败msg：{}",ex.getMessage());
		}catch(Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			logger.error("获取项目报价方案失败msg:{}",ex.getMessage());
		}
		return result;
	}
	/**
	 * 测算
	 */
	@RequestMapping(value = "/calculate.do", method = { RequestMethod.POST })
	@ResponseBody
	public Object calculate(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_ADD_SUCC);
		String isModify = request.getParameter("isModify");//是否修改，当不等额第一次按等额计算
		PrjQuatPrpsVO prjQuatPrps = null;
		Long id  =	 null;
		try {
            // 不还款处理方式（PRJ0015） 暂且借用此字段 做为判断是否使用新报价方法逻辑  测试后去掉
            String noPayWayCd = request.getParameter("noPayWayCd");
			prjQuatPrps = getRequestParams(request);
			//特殊业务类型未选择低息且实际收益率（IRR）≤10%且客户保证金比例≥30%条件时 测算不需要弹窗提示
			prjQuatPrps.setIsNeedOpenWin("1");
            prjQuatPrps.setNoPayWayCd(noPayWayCd);
            PrjBscInfoVO prjBscInfoVO =  this.prjBscInfoService.selectById(prjQuatPrps.getPrjId());
            // 传统/城配业务，需要校验首期比例，不能小于10%
			List<PrjQuatPrpsFeeVO>  feeList = prjQuatPrps.getPrjQuatPrpsFeelist();
			if(CollectionUtils.isNotEmpty(feeList)){
				Double fee117 = 0d,fee118 = 0d ;
				for (PrjQuatPrpsFeeVO prjQuatPrpsFeeVO : feeList) {
					if(prjQuatPrpsFeeVO.getFeeTypCd().equals(PrjQuatPrpsFeeConstant.PRJ_FEE_TYP_FIRST_PRC) && prjBscInfoVO.getBuOrgCd().equals(PrjBscInfoConstant.CODE_BU_ORG_CD_ZK)){
						if((prjBscInfoVO.getPrjTypCd().equals(PrjBscInfoConstant.PRJ_TYP_CD_CPYW) || prjBscInfoVO.getPrjTypCd().equals(PrjBscInfoConstant.PRJ_TYP_CD_CTYW))
								&& BaseConstant.IS_YESNO_NO == prjBscInfoVO.getIsInsBiz() && prjQuatPrpsFeeVO.getFeePct() < 10d){
							throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"我司项目首期费用比例不能小于10%!");
						}
                        if((prjBscInfoVO.getPrjTypCd().equals(PrjBscInfoConstant.PRJ_TYP_CD_CDDYWUL) || prjBscInfoVO.getPrjTypCd().equals(PrjBscInfoConstant.PRJ_TYP_CD_ESCJYD) || PrjBscInfoConstant.PRJ_TYP_CD_OWNJYD.equals(prjBscInfoVO.getPrjTypCd()))
                                && PrjBscInfoConstant.PRJ_INS_CODE_SYFL.equals(prjBscInfoVO.getInsCode()) && prjQuatPrpsFeeVO.getFeePct() < 30d){
                            throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"首期比例不能小于30%!");
                        }
					}
					if (PrjBscInfoConstant.COMPENSATORY_TYPE_2.equals(prjBscInfoVO.getCompensatoryType())){
						if (PrjQuatPrpsFeeConstant.FEE_TYP_CD_117.equals(prjQuatPrpsFeeVO.getFeeTypCd())){
							fee117 = prjQuatPrpsFeeVO.getFeeAmt() == null?0:prjQuatPrpsFeeVO.getFeeAmt() ;
						}
						if (PrjQuatPrpsFeeConstant.FEE_TYP_CD_118.equals(prjQuatPrpsFeeVO.getFeeTypCd())){
							fee118 = prjQuatPrpsFeeVO.getFeeAmt() == null?0:prjQuatPrpsFeeVO.getFeeAmt() ;
						}
					}
				}
				if(prjBscInfoVO.getBuOrgCd().equals(PrjBscInfoConstant.CODE_BU_ORG_CD_ZK)
						&& (prjBscInfoVO.getPrjTypCd().equals(PrjBscInfoConstant.PRJ_TYP_CD_CTYW)
						|| prjBscInfoVO.getPrjTypCd().equals(PrjBscInfoConstant.PRJ_TYP_CD_CPYW))){
					if (fee117 > 0 && fee118 > 0){
						throw new BaseException("担保保证金/垫资保证金不可同时存在") ;
					}
					if (fee117 == 0d && fee118 == 0d && PrjBscInfoConstant.COMPENSATORY_TYPE_2.equals(prjBscInfoVO.getCompensatoryType())){
						throw new BaseException("担保保证金/垫资保证金必须有一项不为0") ;
					}
				} else {
					if (fee117 > 0 || fee118 > 0){
						throw new BaseException("仅重卡新车业务支持担保保证金/垫资保证金") ;
					}
				}
			}
			// 如果开关打开、是重卡传统/城配项目，需计算小贷拿去用额度
			if (prjBscInfoVO.getBuOrgCd().equals(PrjBscInfoConstant.CODE_BU_ORG_CD_ZK)
					&& (prjBscInfoVO.getPrjTypCd().equals(PrjBscInfoConstant.PRJ_TYP_CD_CTYW)
					|| prjBscInfoVO.getPrjTypCd().equals(PrjBscInfoConstant.PRJ_TYP_CD_CPYW))) {
				// 获取小贷拿去用额度计算推送总开关
				SysCtrlCfgQueryCondition sysCtrlCfgQueryCondition = new SysCtrlCfgQueryCondition();
				sysCtrlCfgQueryCondition.setCtrlCode(PropertiesUtils.getProperty(SysCtrlCfgConstant.SYS_CTRL_CFG_SML_SWITCH_CD));
				sysCtrlCfgQueryCondition.setSysCd(WebBaseConstant.SYS_SYS_CD);
				sysCtrlCfgQueryCondition.setOrgCd(WebBaseConstant.SYS_P_ORG_CD);
				String ctrlCode = this.sysCtrlCfgApiService.searchSysCtrlCfgByCtrlCode(sysCtrlCfgQueryCondition);

				// 获取小贷拿去用额度计算推送子开关
				List<SysDictionaryDTO> smallLoanExceptedList = sysDictionaryApiService.searchGroup(CurrentThreadContext.getCurrentSysCd(), prjBscInfoVO.getCstMgrOrgCd(), PrjQuatPrpsConstant.CODE_GRP_SMALLLOAN_SWITCH);
				Boolean onOff = true ;
				for (SysDictionaryDTO sysDictionaryDTO:smallLoanExceptedList){
					if(prjBscInfoVO.getCstMgrOrgCd().startsWith(sysDictionaryDTO.getCode())){
						onOff = true ;
						break ;
					}
					onOff = false ;
				}
				logger.info("总开关：{},子开关：{}",ctrlCode,JSON.toJSONString(smallLoanExceptedList));
				if ("1".equals(ctrlCode) && onOff ){
					Double fisrtPayPct = 0d;
					for (PrjQuatPrpsFeeVO vo : prjQuatPrps.getPrjQuatPrpsFeelist()){
						if (vo.getFeeTypCd().equals(PrjQuatPrpsFeeConstant.PRJ_FEE_TYP_FIRST_PRC)){
							fisrtPayPct = vo.getFeePct();
							break ;
						}
					}
					BaseParamDTO baseParamDto = new BaseParamDTO();
					baseParamDto.setSysCd(WebBaseConstant.SYS_SYS_CD);
					baseParamDto.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD);
					baseParamDto.setServiceCd(WebBaseConstant.FL_SERVICE_SYS_CD);
					DataResultDTO rskResult = externalRcCstBscInfoSearchApiService.getRcRskLvlAndSplStarLevel(prjBscInfoVO.getRcCstBscInfoId(), baseParamDto);
					if (rskResult != null && rskResult.getData() != null){
						RcRskLvlAndSplStarResult lv = (RcRskLvlAndSplStarResult)rskResult.getData();
						Double smallAmt = prjPayInfoForSmallLoanService.calculateSmallAmt(lv.getRskLvlCd2(), lv.getSplStarLevel(), prjQuatPrps.getTotLsItmAmt(), fisrtPayPct);
						if(prjQuatPrps.getIsBp() != null && prjQuatPrps.getIsBp()==1){
							Double temp = smallAmt-prjQuatPrps.getTotLsItmAmt()*0.06*(1-fisrtPayPct/100) ;
							smallAmt=temp>0?temp:0;
						}else if(prjQuatPrps.getIsBp() != null && prjQuatPrps.getIsBp()==2){
							smallAmt=0d;
						}
						if (smallAmt > 0){
							prjQuatPrps.setSmallLoanAmt(DecimalUtils.convertFenToYuan(smallAmt.longValue()));
						}
					}
				}
			}
			logger.info("calculate.do测算方案.调用资管路由请求参数prjQuatPrps:{}",JSON.toJSONString(prjQuatPrps));
			DataResultDTO resultDTO = this.insRouteBscInfoService.routeResPrps(prjQuatPrps, BaseConstant.IS_YESNO_YES);
			logger.info("calculate.do测算方案.调用资管路由返回结果resultDTO:{}",JSON.toJSONString(resultDTO));
			prjQuatPrps.setIsShowIns(BaseConstant.IS_YESNO_NO);
			if(resultDTO!=null && resultDTO.getSuccess() == BaseConstant.IS_YESNO_NO){
				JSONObject resObj = (JSONObject)resultDTO.getData();
				prjQuatPrps.setIsCheckRouteFlag(Integer.valueOf(resObj.get("isCheckRouteFlag").toString()));
				prjQuatPrps.setIsShowIns(BaseConstant.IS_YESNO_YES);
				prjQuatPrps.setIsAllowNonIns(Integer.valueOf(resObj.get("isAllowNonIns").toString()));
				prjQuatPrps.setGctInsResList((List<InsRouteInsResVO>)resObj.get("gctInsResList"));
				prjQuatPrps.setUngctInsResList((List<InsRouteInsResVO>)resObj.get("ungctInsResList"));
				logger.info("calculate.do测算方案.返回结果prjQuatPrps：{}", JSON.toJSONString(prjQuatPrps));
				ListPageVO<PrjQuatPrpsPaySchVO> listPage = new ListPageVO<PrjQuatPrpsPaySchVO>(prjQuatPrps.getPrjQuatPrpsPaySchList(),prjQuatPrps.getPrjQuatPrpsPaySchList().size());
				prjQuatPrps.setPrjQuatPrpsPaySchPage(listPage);
				result.setData(prjQuatPrps);
				return result;
			}
			if(StringUtils.isBlank(isModify)||isModify.equals("false")){
				prjQuatPrps.setIsModify(BaseConstant.IS_YESNO_NO);
				//第一次
				if(prjQuatPrps.getPayWayCd().equals(PrjQuatPrpsConstant.CODE_BEGI_NO_EQUAL)){
					prjQuatPrps.setPayWayCd(PrjQuatPrpsConstant.CODE_BEGI_EQUAL__PRINC_INTER);
				}
				if(prjQuatPrps.getPayWayCd().equals(PrjQuatPrpsConstant.CODE_END_NO_EQUAL)){
					prjQuatPrps.setPayWayCd(PrjQuatPrpsConstant.CODE_END_EQUAL__PRINC_INTER);
				}	
			}
			//测算
			prjQuatPrps.setSysCd(CurrentThreadContext.getCurrentSysCd());
			prjQuatPrps.setOrgCd(prjBscInfoVO.getCstMgrOrgCd());
			if(StringUtils.isNotEmpty(prjBscInfoVO.getInsCode())){
				prjQuatPrps.setInsCode(prjBscInfoVO.getInsCode());
			}
			if(prjBscInfoVO.getBuOrgCd().equals(PrjBscInfoConstant.CODE_BU_ORG_CD_ZK) &&prjBscInfoVO.getIsSplMfr().intValue()== BaseConstant.IS_YESNO_YES&&null!=prjBscInfoVO.getCalId()&&StringUtils.isBlank(prjBscInfoVO.getInsCode())){
                prjQuatPrps = this.prjQuatPrpsService.prjQuatPrpsCalculateForMfr(prjQuatPrps);
            }else{
				if(PrjBscInfoConstant.PRJ_TYP_CD_CDDYWYQ.equals(prjBscInfoVO.getPrjTypCd())){
					prjQuatPrps = this.prjQuatPrpsService.prjQuatPrpsCalculateYq(prjQuatPrps);
				}else{
					prjQuatPrps = this.prjQuatPrpsService.prjQuatPrpsCalculate(prjQuatPrps);
				}
            }

			//必须是资管且必须支持厂商
			if (BaseConstant.IS_YESNO_YES == prjBscInfoVO.getIsInsBiz()  &&  BaseConstant.IS_YESNO_YES == prjBscInfoVO.getIsSplMfr()) {
				//立项申请选的机构和厂商报价选的机构模式是否一致
				boolean isDifference  = this.validatorCheckedInsCodeModel(prjBscInfoVO);
				if (!isDifference) {
					throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"资管机构模式与预筛选不一致");
				}
			}



			ListPageVO<PrjQuatPrpsPaySchVO> listPage = new ListPageVO<PrjQuatPrpsPaySchVO>(prjQuatPrps.getPrjQuatPrpsPaySchList(),prjQuatPrps.getPrjQuatPrpsPaySchList().size());
			prjQuatPrps.setPrjQuatPrpsPaySchPage(listPage);
			result.setData(prjQuatPrps);
			logger.info("calculate.do测算方案.测算结果：prjQuatPrps:{}", JSON.toJSONString(prjQuatPrps))
					;
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			/*Map<String,Object> map = new HashMap<>(16);
			if(ex.getCode() != null && ex.getCode().equals("000000")){
				map.put("isNeedOpenWin","1");
			}else{
				map.put("isNeedOpenWin","0");
			}
			result.setData(map);*/
			logger.info("calculate.do测算方案.测算数据失败：prjQuatPrps:{}", JSON.toJSONString(prjQuatPrps));
			ex.printStackTrace();
		}catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			logger.error("calculate.do测算方案.测算数据失败：prjQuatPrps:{}", JSON.toJSONString(prjQuatPrps));
			ex.printStackTrace();
		}

		return result;
	}
	/**
	 * 修改状态
	 */
	@RequestMapping(value = "/modifyIsFormalPrpsStatus.do", method = { RequestMethod.POST })
	@ResponseBody
	public Object modifyIsFormalPrpsStatus(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String prjId = request.getParameter("prjId");
		String id  = request.getParameter("id");
		String isFormalPrps = request.getParameter("isFormalPrps");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_ADD_SUCC);
		PrjQuatPrpsVO prjQuatPrps = null;
		try {
			prjQuatPrps =new PrjQuatPrpsVO();
			if(StringUtils.isNotBlank(prjId)){
				prjQuatPrps.setPrjId(Long.valueOf(prjId));
			}
			if(StringUtils.isNotBlank(id)){
				prjQuatPrps.setId(Long.valueOf(id));
			}
			
			if(StringUtils.isNotBlank(isFormalPrps)){
				prjQuatPrps.setIsFormalPrps(Integer.valueOf(isFormalPrps));
			}
			//修改
			prjQuatPrps.setMdfTm(new Date());
			prjQuatPrps.setMdfUsrId(CurrentThreadContext.getCurrentUserId());
			 this.prjQuatPrpsService.modifyIsFormalPrpsStatus(prjQuatPrps);
			logger.info("修改报价方案状态prjQuatPrps:{},id:{}", JSON.toJSONString(prjQuatPrps), id);
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			logger.error("修改报价方案状态失败prjQuatPrps:{},id:{}", JSON.toJSONString(prjQuatPrps),id);
		}catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			logger.error("修改报价方案状态失败prjQuatPrps：{},id:{}", JSON.toJSONString(prjQuatPrps), id);
		}

		return result;
	}

	
	/**
	 * 新增
	 */
	@RequestMapping(value = "/add.do", method = { RequestMethod.POST })
	@ResponseBody
	public Object add(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String quatId = request.getParameter("id");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_ADD_SUCC);
		PrjQuatPrpsVO prjQuatPrps = null;
		Long id  =	 null;
		try {
			prjQuatPrps = getRequestParams(request);
			if(StringUtils.isNotBlank(quatId)){
				prjQuatPrps.setId(Long.valueOf(quatId));
				prjQuatPrps.setMdfUsrId(CurrentThreadContext.getCurrentUserId());
				prjQuatPrps.setMdfTm(new Date());
				//修改
				this.prjQuatPrpsService.modify(prjQuatPrps);
				id = Long.valueOf(quatId);
			}else{
				//添加
				prjQuatPrps.setCrtTm(new Date());
				prjQuatPrps.setCrtUsrId(CurrentThreadContext.getCurrentUserId());
				id = this.prjQuatPrpsService.add(prjQuatPrps);
			}
			
			result.setData(id);
			logger.info("新增报价方案prjQuatPrps:{}", JSON.toJSONString(prjQuatPrps));
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			Map<String,Object> map = new HashMap<>(16);
			if(ex.getCode() != null && ex.getCode().equals("000000")){
				map.put("isNeedOpenWin","0");
			}else{
				map.put("isNeedOpenWin","1");
			}
			result.setData(map);
			logger.error("新增报价方案失败prjQuatPrps:{},msg:{}", JSON.toJSONString(prjQuatPrps),ex.getMessage());
		}catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			logger.error("新增报价方案失败prjQuatPrps:{},msg:{}", JSON.toJSONString(prjQuatPrps),ex.getMessage());
		}

		return result;
	}

	private PrjQuatPrpsVO getRequestParams(HttpServletRequest request) {
		PrjQuatPrpsVO prjQuatPrps = new PrjQuatPrpsVO();
		String prjId = request.getParameter("prjId");//项目ID
		String specialBusinessType = request.getParameter("specialBusinessType");//特殊业务类型
		String totLsItmAmt = request.getParameter("totLsItmAmt");//租赁物件总价值（元）
		String contAmt = request.getParameter("contAmt");//合同总额
		String lsPd = request.getParameter("lsPd");//租赁期数
		String lsPdUntCd = request.getParameter("lsPdUntCd");//租赁期数单位
		String annIntRatePct = request.getParameter("annIntRatePct");//租赁年利率
		String intRateRsPct = request.getParameter("intRateRsPct");//利率上浮比例
		String payWayCd = request.getParameter("payWayCd");//支付方式
		String actLsAmt = request.getParameter("actLsAmt");//实际融资租赁价值（元）
		String eachEstRntAmt = request.getParameter("eachEstRntAmt");// 每期预估租金（元）
		String lsCalWayCd = request.getParameter("lsCalWayCd");//租赁计算方式（PRJ0012）
		String intRateWayCd = request.getParameter("intRateWayCd");// 租赁年利率计算方式（PRJ0011）
		String lsCoe = request.getParameter("lsCoe");// 租赁系数
		String dpstHdlWayCd = request.getParameter("dpstHdlWayCd");//保证金处理方式（PRJ0013）
		String expHdlWayCd = request.getParameter("expHdlWayCd");//租赁期满处理方式（PRJ0014）
		/*String noPayWayCd = request.getParameter("noPayWayCd");// 不还款处理方式（PRJ0015）
*/		String detailList = request.getParameter("feeDetailList");//方案费用明细
		String payList = request.getParameter("payList");//支付信息
		String prpsCfgId = request.getParameter("prpsCfgId");
		String prpsCfgNm = request.getParameter("prpsCfgNm");
		String irrPct = request.getParameter("irrPct");//实际收益率
		String isAllowAdd = request.getParameter("isAllowAdd");// 是否允许添加费用项
		String isAllowChg =  request.getParameter("isAllowChg");// 是否可以修改
		String prpsTypCd = request.getParameter("prpsTypCd");//方案类型
		String quatSplitPct = request.getParameter("quatSplitPct");//拆分比例
		String contDetailList = request.getParameter("contFeeDetailList");
		String initLsPct = request.getParameter("initLsPct");//第一年比例
		String mfrDiscountRate = request.getParameter("mfrDiscountRate");
		String preRntPct = request.getParameter("preRntPct");
		String lsPd2 = request.getParameter("lsPd2");//重卡工行上装期数/新能源经营性租赁业务
		String isBp = request.getParameter("isBp");// 是否包牌
		String businessInsCd = request.getParameter("businessInsCd");
		String tempActLsAmt = request.getParameter("tempActLsAmt");//新能源直租补录数据临时融资额
		String policyTypCd = request.getParameter("policyTypCd");//方案政策类型（重卡厂商业务使用）
        String tenThouCoef = request.getParameter("tenThouCoef");
        String isLowDownPayment = request.getParameter("isLowDownPayment");// 是否使用低首付产品
        String chlDpstPwayCd = request.getParameter("chlDpstPwayCd") ;
        String rtnPdStart = request.getParameter("rtnPdStart") ;
        String rtnPdEnd = request.getParameter("rtnPdEnd") ;
        String isLowBiz = request.getParameter("isLowBiz");//是否低息
		String speLsPd = request.getParameter("speLsPd");
		String oneCityOnePolicyTypeCd = request.getParameter("oneCityOnePolicyTypeCd");
		// 是否捆绑租金补助
		String rentAllowanceService = request.getParameter("rentAllowanceService");
		logger.info("项目id:{},是否捆绑租金补助服务的值:{}",prjId,rentAllowanceService);

		prjQuatPrps.setPrjId(Long.valueOf(prjId));
		double invoiceA = 0d; // 发票价格 -- 目前只有浦发用
		double bupiaoAmt = 0d; // 补票金额 -- 目前只有浦发用
		double insuranceAmt = 0d;// 保险费 -- 目前只有浦发用
		double vehiclePurchaseTax  = 0d ;//购置税（浦发叫车辆购置税） -- 目前只有浦发用
		double gpsOtherAmt = 0d; // gps及其他费用 -- 目前只有浦发用

        String annIntRatePct2 = request.getParameter("annIntRatePct2");//租赁年利率2 //厂商系统使用
		//传统城配保存方案时如果未选择低息 且满足保证金抵租金流程 是否弹窗
		String isNeedOpenWin = request.getParameter("isNeedOpenWin");
		if(StringUtils.isNotBlank(isNeedOpenWin)){
			prjQuatPrps.setIsNeedOpenWin(isNeedOpenWin);
		}

		if(StringUtils.isNotBlank(specialBusinessType)){
			prjQuatPrps.setSpecialBusinessType(specialBusinessType);
		}
		//报价方案属性新增是否低息字段
		if(StringUtils.isNotBlank(isLowBiz)){
			prjQuatPrps.setIsLowBiz(Integer.valueOf(isLowBiz));
		}

        if(StringUtils.isNotBlank(annIntRatePct2)){
            prjQuatPrps.setAnnIntRatePct2(Double.valueOf(annIntRatePct2));
        }

        // 是否捆绑租金补助服务
		if(StringUtils.isNotBlank(rentAllowanceService)) {
			prjQuatPrps.setRentAllowanceService(Integer.valueOf(rentAllowanceService));
		}

		if(StringUtils.isNotBlank(oneCityOnePolicyTypeCd)){
			prjQuatPrps.setOneCityOnePolicyTypeCd(oneCityOnePolicyTypeCd);
		}else{
			prjQuatPrps.setOneCityOnePolicyTypeCd("no");
		}


		boolean flag = false;//是否有厂商利率费用项
		PrjBscInfoVO bscInfoVO = this.prjBscInfoService.selectById(Long.valueOf(prjId));

		//事业部
        String buOrgCd = bscInfoVO.getBuOrgCd();

        //项目类型
        String prjTypCd = bscInfoVO.getPrjTypCd();

/*		if(bscInfoVO.getBuOrgCd().equals(PrjBscInfoConstant.CODE_BU_ORG_CD_ZK)&&StringUtils.isNotBlank(bscInfoVO.getPrjTypCd())&&
				(bscInfoVO.getPrjTypCd().equals(PrjBscInfoConstant.PRJ_TYP_CD_CSYWCP)||bscInfoVO.getPrjTypCd().equals(PrjBscInfoConstant.PRJ_TYP_CD_CSYWCT))){
			if(StringUtils.isBlank(irrPct)){
				throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"请填写IRR的值!");
			}
		}
*/

        //厂商业务验证
        /*Map<String,String> map = new HashMap<String,String>();
        List<SysDictionaryDTO>  mfrList = this.sysDictionaryApiService.searchGroup(CurrentThreadContext.getCurrentSysCd(), bscInfoVO.getBuOrgCd(), DictionaryConstant.CODE_IS_NOT_SUPP_MFR);
        if(CollectionUtils.isNotEmpty(mfrList)){
            for (SysDictionaryDTO sysDictionaryDTO : mfrList) {
                map.put(sysDictionaryDTO.getCode(),sysDictionaryDTO.getCodeNm());
            }
        }
        BaseLogUtils.info(logger, "modify", "map" + JSONObject.toJSONString(map), CurrentThreadContext.getCurrentUserName());

        boolean mfrFlag = true;
        PrjPrdBscInfoQueryCondition  prdQc = new PrjPrdBscInfoQueryCondition();
        prdQc.setPrjId(bscInfoVO.getId());
        List<PrjPrdBscInfoVO>  prdList = this.prjPrdBscInfoService.searchList(prdQc);
        if(CollectionUtils.isNotEmpty(prdList)&&CollectionUtils.isNotEmpty(mfrList)){
            for(PrjPrdBscInfoVO prjPrdBscInfo:prdList){
                if(map.containsKey(String.valueOf(prjPrdBscInfo.getSplMfrId()))&&!prjPrdBscInfo.getPrdTypCd().equals(PrjPrdBscInfoConstant.PRD_TYP_CD_9)){
                    mfrFlag = false;
                    if(null!=bscInfoVO.getIsSplMfr()&&bscInfoVO.getIsSplMfr()==BaseConstant.IS_YESNO_YES
                            &&map.containsKey(String.valueOf(prjPrdBscInfo.getSplMfrId()))&&null!=bscInfoVO.getCalId()){
                        throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,map.get(prjPrdBscInfo.getSplMfrId()+"")+"不支持资管业务!");
                    }
                }
            }
        }
        if(mfrFlag&&null!=bscInfoVO.getIsSplMfr()&&bscInfoVO.getIsSplMfr()==BaseConstant.IS_YESNO_YES&&null==bscInfoVO.getCalId()){
            throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"请选择厂商报价器!");
        }*/
        if(null!=bscInfoVO.getIsSplMfr()&&bscInfoVO.getIsSplMfr()== BaseConstant.IS_YESNO_YES&&null==bscInfoVO.getCalId()){
        	if (!PrjBscInfoConstant.CODE_BU_ORG_CD_XNY.equals(bscInfoVO.getBuOrgCd()) || !PrjBscInfoConstant.PRJ_TYP_CD_CPYW.equals(bscInfoVO.getPrjTypCd())){
				throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"请选择厂商报价器!");
			}
        }
        if(StringUtils.isNotBlank(tenThouCoef)){
            prjQuatPrps.setTenThouCoef(DecimalUtils.convertYuanToFen(Double.valueOf(tenThouCoef)).doubleValue());
        }
		if(StringUtils.isNotBlank(policyTypCd)){
			prjQuatPrps.setPolicyTypCd(policyTypCd);
		}
		if(StringUtils.isNotBlank(tempActLsAmt)){
			prjQuatPrps.setTempActLsAmt(DecimalUtils.convertYuanToFen(Double.valueOf(tempActLsAmt)).doubleValue());
		}
		if(StringUtils.isNotBlank(isBp)){
			prjQuatPrps.setIsBp(Integer.valueOf(isBp));
		}
		if(StringUtils.isNotBlank(businessInsCd)){
			prjQuatPrps.setBusinessInsCd(businessInsCd);
		}
		if(StringUtils.isNotBlank(lsPd2)){
			prjQuatPrps.setLsPd2(Long.valueOf(lsPd2));
		}

		if(StringUtils.isNotBlank(isAllowChg)){
			prjQuatPrps.setIsAllowChg(isAllowChg);
		}
		if(StringUtils.isNotBlank(isAllowAdd)){
			prjQuatPrps.setIsAllowAdd(Integer.valueOf(isAllowAdd));
		}
		if(StringUtils.isNotBlank(irrPct)){
			prjQuatPrps.setIrrPct(Double.valueOf(irrPct));
		}
		if(StringUtils.isNotBlank(prpsTypCd)){
			prjQuatPrps.setPrpsTypCd(prpsTypCd);
		}
		if(StringUtils.isNotBlank(initLsPct)){
			prjQuatPrps.setInitLsPct(Double.valueOf(initLsPct));
		}
		if(StringUtils.isNotBlank(prpsCfgId)){
			prjQuatPrps.setPrpsCfgId(Long.valueOf(prpsCfgId));
		}
		if(StringUtils.isBlank(quatSplitPct)){
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"报价版方案拆分比例不能为空!");
		}
		prjQuatPrps.setQuatSplitPct(Double.valueOf(quatSplitPct));
		/*if(StringUtils.isNotBlank(irrPct)){
			prjQuatPrps.setIrrPct(Double.valueOf(irrPct));
		}*/
			prjQuatPrps.setPrpsCfgNm(prpsCfgNm);
		if(StringUtils.isNotBlank(lsCoe)){
			prjQuatPrps.setLsCoe(Double.valueOf(lsCoe));
		}
		if(StringUtils.isNotBlank(intRateRsPct)){
			prjQuatPrps.setIntRateRsPct(Double.valueOf(intRateRsPct));
		}
		if(StringUtils.isNotBlank(actLsAmt)){
			prjQuatPrps.setActLsAmt(DecimalUtils.convertYuanToFen(Double.valueOf(actLsAmt)).doubleValue());

		}
		if(StringUtils.isNotBlank(isLowDownPayment)){
			prjQuatPrps.setIsLowDownPayment(Integer.valueOf(isLowDownPayment));
		}
        if (StringUtils.isNotBlank(chlDpstPwayCd)){
            prjQuatPrps.setChlDpstPwayCd(chlDpstPwayCd);
        }
        if (StringUtils.isNotBlank(rtnPdStart)){
            prjQuatPrps.setRtnPdStart(Integer.valueOf(rtnPdStart));
        }
        if (StringUtils.isNotBlank(rtnPdEnd)){
            prjQuatPrps.setRtnPdEnd(Integer.valueOf(rtnPdEnd));
        }
		if(StringUtils.isNotBlank(eachEstRntAmt)){
			prjQuatPrps.setEachEstRntAmt(DecimalUtils.convertYuanToFen(Double.valueOf(eachEstRntAmt)).doubleValue());
		}

		if(StringUtils.isEmpty(intRateWayCd)){
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"租赁年利率计算方式不能为空!");
		}
		prjQuatPrps.setIntRateWayCd(intRateWayCd);
		if(StringUtils.isEmpty(lsPdUntCd)){
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"租赁期数单位不能为空!");
		}
		prjQuatPrps.setLsPdUntCd(lsPdUntCd);
		if(StringUtils.isEmpty(totLsItmAmt)){
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"租赁物件总价值不能为空!");
		}
		if(!StringUtils.isUnsignedNumeric(totLsItmAmt)){
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"租赁物件总价值应为数字!");
		}
		prjQuatPrps.setTotLsItmAmt(DecimalUtils.convertYuanToFen(Double.valueOf(totLsItmAmt)).doubleValue());
		if(StringUtils.isEmpty(contAmt)){
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"合同总额不能为空!");
		}
		if(!StringUtils.isUnsignedNumeric(contAmt)){
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"合同总额应为数字!");
		}
		prjQuatPrps.setContAmt(DecimalUtils.convertYuanToFen(Double.valueOf(contAmt)).doubleValue());
		if(StringUtils.isEmpty(lsPd)){
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"租赁期数不能为空!");
		}
		if(!StringUtils.isNumeric(lsPd)){
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"租赁期数应为数字!");
		}
		prjQuatPrps.setLsPd(Long.valueOf(lsPd));
		if(StringUtils.isEmpty(payWayCd)){
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"支付方式不能为空!");
		}else{
			if(payWayCd.equals(PrjQuatPrpsConstant.CODE_SING_MONTH_NO_PAY)){
				throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"暂不支持该支付方式，请选择其他支付方式!");
			}
		}
		if (PrjBscInfoConstant.PRJ_INS_CODE_XBFL.equals(bscInfoVO.getInsCode()) && PrjBscInfoConstant.PRJ_TYP_CD_ESCJYD.equals(prjTypCd)){
			if( !lsPd.equals("6") && !lsPd.equals("12") && !lsPd.equals("18") && !lsPd.equals("24")){
				throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"仅支持6,12,18,24期!");
			}
		}
		if(PrjQuatPrpsConstant.PAY_WAY_CD_19.equals(payWayCd)
				||PrjQuatPrpsConstant.PAY_WAY_CD_20.equals(payWayCd)){
			if(!lsPd.equals("24") && !lsPd.equals("36")){
				throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"仅支持24,36期!");
			}
		}
		if(PrjQuatPrpsConstant.PAY_WAY_CD_21.equals(payWayCd)){
			if(!lsPd.equals("12") && !lsPd.equals("18") && !lsPd.equals("24") && !lsPd.equals("36")){
				throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"仅支持12,18,24,36期!");
			}
		}
		if(payWayCd.equals(PrjQuatPrpsConstant.PAY_WAY_CD_19)){
			if(StringUtils.isEmpty(speLsPd)){
				throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"不还款期数不能为空!");
			}
			String[] split = speLsPd.split(",");
			if(split.length != 2){
				throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"不还款期数格式错误!");
			}
			if(!StringUtils.isNumeric(split[0]) || !StringUtils.isNumeric(split[1])){
				throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"不还款期数格式错误!");
			}
			if(Long.valueOf(split[0])<7
					|| Long.valueOf(split[0])>(Long.valueOf(lsPd) - 6)
					|| Long.valueOf(split[1])<7
					|| Long.valueOf(split[1])>(Long.valueOf(lsPd) - 6)){
				throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"不还款期数7-" + (Long.valueOf(lsPd) - 6) + "!");
			}
			if(split[0].equals(split[1])){
				throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"不还款期数相同!");
			}
			prjQuatPrps.setSpeLsPd(speLsPd);
		}else{
			prjQuatPrps.setSpeLsPd("");
		}
		prjQuatPrps.setPayWayCd(payWayCd);
		if(!prjQuatPrps.getPayWayCd().equals(PrjQuatPrpsConstant.CODE_MULTI__STEP_INTER_IRR)/*&&!prjQuatPrps.getPayWayCd().equals(PrjQuatPrpsConstant.CODE_MULTI__STEP_INTER_GH)*/){
			if(StringUtils.isEmpty(annIntRatePct)){
				throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"租赁年利率不能为空!");
			}
			if(!StringUtils.isUnsignedNumeric(annIntRatePct)){
				throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"租赁年利率应为数字!");
			}
			/**
			 * REQ-15169 天津银行资管优化
			 * 校验年利率是否为小数点后两位
			 * 若超过两位，则弹窗提示“天津银行租赁年利率仅支持小数点后两位，请修改”
			 */
			if (StringUtils.isNotBlank(bscInfoVO.getInsCode()) && (PrjBscInfoConstant.PRJ_INS_CODE_TIANJINBANK.equals(bscInfoVO.getInsCode()))) {
				int pointNum = (annIntRatePct+"").length() - (annIntRatePct+"").indexOf(".") -1;
				if (pointNum > 2) {
					throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"天津银行租赁年利率仅支持小数点后两位，请修改");
				}
			}
		}
		prjQuatPrps.setAnnIntRatePct(Double.valueOf(annIntRatePct));
        if((bscInfoVO.getBuOrgCd().equals(PrjBscInfoConstant.CODE_BU_ORG_CD_ZK)||bscInfoVO.getBuOrgCd().equals(PrjBscInfoConstant.CODE_BU_ORG_CD_YC))
                &&payWayCd.equals(PrjQuatPrpsConstant.CODE_MULTI__STEP_INTER)&&StringUtils.isBlank(preRntPct)){
            throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"支付方式为阶梯还款时，请选择前期租金比率!");
        }

        if(StringUtils.isNotBlank(preRntPct)){
            prjQuatPrps.setPreRntPct(Double.valueOf(preRntPct));
        }
		if(StringUtils.isEmpty(lsCalWayCd)){
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"租赁计算方式不能为空!");
		}
		prjQuatPrps.setLsCalWayCd(lsCalWayCd);
		if(StringUtils.isEmpty(dpstHdlWayCd)){
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"保证金处理方式不能为空!");
		}
		prjQuatPrps.setDpstHdlWayCd(dpstHdlWayCd);
		if(StringUtils.isEmpty(expHdlWayCd)){
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"租赁期满处理方式不能为空!");
		}
		prjQuatPrps.setExpHdlWayCd(expHdlWayCd);
		/*if(StringUtils.isEmpty(noPayWayCd)){
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"不还款处理方式不能为空!");
		}
		prjQuatPrps.setNoPayWayCd(noPayWayCd);*/
		List<PrjQuatPrpsFeeVO> list = new ArrayList<PrjQuatPrpsFeeVO>();
		List<PrjQuatPrpsFeeVO> contFeeList = new ArrayList<PrjQuatPrpsFeeVO>();
		if (StringUtils.isBlank(detailList)) {
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"费用项不能为空!");
		}
		if(StringUtils.isNotBlank(contDetailList)){
			contFeeList = JSON.parseArray(contDetailList, PrjQuatPrpsFeeVO.class);
		}
		if (StringUtils.isNotBlank(detailList)) {
			list = JSON.parseArray(detailList, PrjQuatPrpsFeeVO.class);
		}

		String id = request.getParameter("id");
		double backAmt = 0d;//返利金额
		double ghBackAmt = 0d;//工行返利金额
		double consltPct =0d;//总的返利比例
		double firstPct = 0d;//首付比例
		double splBack=0d;//供应商返利
		double consltSplBack=0d;//咨询费供应商返利
		double consltSalBak =0d;//咨询费销售返利
		double salBack = 0d;//销售返利
        double spdFee30Amt=0d;//购置税
		/**
		 * 客户保证金比例
		 */
		double collateralPct = 0d;
		//  TODO 浦发 记录费用项
		Map<String,Boolean> spdFeeMap = new HashMap<String,Boolean>();
		spdFeeMap.put(PrjQuatPrpsFeeConstant.FEE_TYP_CD_30,false);
		spdFeeMap.put(PrjQuatPrpsFeeConstant.FEE_TYP_CD_67,false);
		boolean fee63 = false;
		for (PrjQuatPrpsFeeVO prjQuatPrpsFeeVO : list) {
			if(prjQuatPrpsFeeVO.getFeeTypCd().equals(PrjQuatPrpsFeeConstant.FEE_TYP_CD_63)){
				Double feeAmt = prjQuatPrpsFeeVO.getFeeAmt();
				if(feeAmt != null && feeAmt>0){
					fee63 = true;
				}
			}
			if(prjQuatPrpsFeeVO.getFeeTypCd().equals(PrjQuatPrpsConstant.CODE_FEE_WAY_TYPE_DOWNPAY)){
				firstPct = prjQuatPrpsFeeVO.getFeePct();
			}
			if(prjQuatPrpsFeeVO.getFeeTypCd().equals(PrjQuatPrpsFeeConstant.PRJ_FEE_TYP_COLLATERAL)){
				collateralPct = prjQuatPrpsFeeVO.getFeePct();
			}
			if(prjQuatPrpsFeeVO.getFeeTypCd().equals(PrjQuatPrpsFeeConstant.PRJ_FEE_TYP_CONSULT_1)){
				consltPct = prjQuatPrpsFeeVO.getFeePct();
			}
			if(prjQuatPrpsFeeVO.getFeeTypCd().equals(PrjQuatPrpsFeeConstant.FEE_TYP_CD_61)){
				backAmt = prjQuatPrpsFeeVO.getFeeAmt();
			}
			if(prjQuatPrpsFeeVO.getFeeTypCd().equals(PrjQuatPrpsFeeConstant.FEE_TYP_CD_57)){
				ghBackAmt = prjQuatPrpsFeeVO.getFeeAmt();
			}
			//供应商返利
			if(prjQuatPrpsFeeVO.getFeeTypCd().equals(PrjQuatPrpsFeeConstant.FEE_TYP_CD_08)){
				splBack = prjQuatPrpsFeeVO.getFeeAmt();

				//  重卡事业部传统业务/城配业务
                if (PrjBscInfoConstant.CODE_BU_ORG_CD_ZK.equals(buOrgCd) &&StringUtils.isNotBlank(prjTypCd) && (PrjBscInfoConstant.PRJ_TYP_CD_CPYW.equals(prjTypCd)  || PrjBscInfoConstant.PRJ_TYP_CD_CTYW.equals(prjTypCd))) {

                    if (splBack > 0) {
                        throw new BaseException("供应商返利金额大于0");
                    }
                }
			}
			//销售返利
			if(prjQuatPrpsFeeVO.getFeeTypCd().equals(PrjQuatPrpsFeeConstant.FEE_TYP_CD_49)){
				salBack = prjQuatPrpsFeeVO.getFeeAmt();

                //  重卡事业部传统业务/城配业务
                if (PrjBscInfoConstant.CODE_BU_ORG_CD_ZK.equals(buOrgCd) &&StringUtils.isNotBlank(prjTypCd) && (PrjBscInfoConstant.PRJ_TYP_CD_CPYW.equals(prjTypCd)  || PrjBscInfoConstant.PRJ_TYP_CD_CTYW.equals(prjTypCd))) {

                    if (salBack > 0) {
                        throw new BaseException("销售返利金额大于0");
                    }
                }
			}

			// 留购价
			if(PrjQuatPrpsFeeConstant.PRJ_FEE_TYP_PURCHASE.equals(prjQuatPrpsFeeVO.getFeeTypCd())) {
					double feePurchase = null == prjQuatPrpsFeeVO.getFeeAmt() ? 0 : prjQuatPrpsFeeVO.getFeeAmt();
					logger.info("项目id:{},留购价:{}",prjId,feePurchase);

					// 浙银金租
					if (StringUtils.isNotBlank(bscInfoVO.getInsCode()) && (PrjBscInfoConstant.PRJ_INS_CODE_ZYFL.equals(bscInfoVO.getInsCode()))) {
						if (feePurchase != 0) {
							throw new BaseException("留购价必须为0，请修改");
						}
					}
			}


			// 当机构为新网银行，校验字段 是否包牌
			if (StringUtils.isNotBlank(bscInfoVO.getInsCode()) && PrjBscInfoConstant.PRJ_INS_CODE_XWBANK.equals(bscInfoVO.getInsCode())) {
				/**
				 * 校验是否包牌
				 */
				// 包购置税
				if (String.valueOf(PrjQuatPrpsConstant.CODE_IS_BP_1).equals(isBp)) {
					// 购置税
					if (PrjQuatPrpsFeeConstant.FEE_TYP_CD_30.equals(prjQuatPrpsFeeVO.getFeeTypCd())) {
						logger.info("项目id:{}，费用类型:{}",prjId,prjQuatPrpsFeeVO.getFeeTypCd());
						double	purchaseTax =  null == prjQuatPrpsFeeVO.getFeeAmt() ? 0 : prjQuatPrpsFeeVO.getFeeAmt();
						logger.info("项目id:{}，是否包牌:{},购置税:{}",prjId,isBp,purchaseTax);

						if (purchaseTax <= 0) {
							throw new BaseException("购置税小于等于0，请重新填写!");
						}
					}
				}
				// 包购置税和保险
				else if (String.valueOf(PrjQuatPrpsConstant.CODE_IS_BP_2).equals(isBp)) {

					// 购置税 保险费
					if (PrjQuatPrpsFeeConstant.FEE_TYP_CD_30.equals(prjQuatPrpsFeeVO.getFeeTypCd()) || PrjQuatPrpsFeeConstant.FEE_TYP_CD_67.equals(prjQuatPrpsFeeVO.getFeeTypCd())) {
						logger.info("项目id:{}，是否包牌:{},费用类型:{},费用金额:{}",prjId,isBp,prjQuatPrpsFeeVO.getFeeTypCd(),prjQuatPrpsFeeVO.getFeeAmt());
						double feeAmt =  null == prjQuatPrpsFeeVO.getFeeAmt() ? 0 : prjQuatPrpsFeeVO.getFeeAmt();
						logger.info("项目id:{}，是否包牌:{},费用金额:{}",prjId,isBp,feeAmt);

						if (feeAmt <= 0 ) {
							throw new BaseException("购置税、保险费小于等于0，请重新填写!");
						}
					}
				}
			}


			if(prjQuatPrpsFeeVO.getFeeTypCd().equals(PrjQuatPrpsFeeConstant.FEE_TYP_CD_71)){
				consltSplBack = prjQuatPrpsFeeVO.getFeeAmt();
			}
			if(prjQuatPrpsFeeVO.getFeeTypCd().equals(PrjQuatPrpsFeeConstant.FEE_TYP_CD_72)){
				consltSalBak = prjQuatPrpsFeeVO.getFeeAmt();
			}

			if(bscInfoVO.getBuOrgCd().equals(PrjBscInfoConstant.CODE_BU_ORG_CD_ZK) &&prjQuatPrpsFeeVO.getFeeTypCd().equals(PrjQuatPrpsFeeConstant.FEE_TYP_CD_54)){
				prjQuatPrpsFeeVO.setFeePct(Double.valueOf(mfrDiscountRate));
				flag = true;
			}
			//  TODO 浦发 记录费用项 是否为空
			// 如果是浦发银行项目 计算和验证必填费用项
			if(StringUtils.isNotBlank(bscInfoVO.getInsCode())&&bscInfoVO.getInsCode().equals(PrjBscInfoConstant.PRJ_INS_CODE_SPD)){

				if(StringUtils.isNotEmpty(isBp) && ("1".equals(isBp) || "2".equals(isBp) )){
					if(prjQuatPrpsFeeVO.getFeeTypCd().equals(PrjQuatPrpsFeeConstant.FEE_TYP_CD_30)){//购置税（浦发叫车辆购置税） (发票金额/11.7)
						spdFeeMap.put(prjQuatPrpsFeeVO.getFeeTypCd(),true);
						spdFee30Amt = prjQuatPrpsFeeVO.getFeeAmt();
						if(null==prjQuatPrpsFeeVO.getFeeAmt()||prjQuatPrpsFeeVO.getFeeAmt()==0d){
							throw new BaseException("费用项购置税，不能为空!");
						}
						if(DecimalUtils.convertYuanToFen(spdFee30Amt)>prjQuatPrps.getContAmt()/11.3){
							throw new BaseException("项购置税过高，请调整!");
						}
					}
				}

				if(prjQuatPrpsFeeVO.getFeeTypCd().equals(PrjQuatPrpsFeeConstant.FEE_TYP_CD_67)){//险费
					spdFeeMap.put(prjQuatPrpsFeeVO.getFeeTypCd(),true);
				}

			}


			//上海农商
			if(StringUtils.isNotBlank(bscInfoVO.getInsCode()) && bscInfoVO.getInsCode().equals(PrjBscInfoConstant.PRJ_INS_CODE_SHNS)){

                //保险费
			    if(PrjQuatPrpsFeeConstant.FEE_TYP_CD_67.equals(prjQuatPrpsFeeVO.getFeeTypCd())){
					spdFeeMap.put(prjQuatPrpsFeeVO.getFeeTypCd(),true);

                    if(null == prjQuatPrpsFeeVO.getFeeAmt() || prjQuatPrpsFeeVO.getFeeAmt() <= 0d){
                        throw new BaseException("保险费小于等于0，请重新填写!");

                    } else {
                        logger.info("上海农商的保险费不是空，金额为："+ prjQuatPrpsFeeVO.getFeeAmt());
                    }
				}

                //购置税
				if(PrjQuatPrpsFeeConstant.FEE_TYP_CD_30.equals(prjQuatPrpsFeeVO.getFeeTypCd())){
					spdFeeMap.put(prjQuatPrpsFeeVO.getFeeTypCd(),true);

					if(null == prjQuatPrpsFeeVO.getFeeAmt() || prjQuatPrpsFeeVO.getFeeAmt() <= 0d){
						throw new BaseException("购置税小于等于0，请重新填写!");

					} else {
                        logger.info("上海农商的购置税不是空，金额为："+ prjQuatPrpsFeeVO.getFeeAmt());
                    }
                }
			}


		/*	if(prjQuatPrpsFeeVO.getFeeTypCd().equals(PrjQuatPrpsFeeConstant.PRJ_FEE_TYP_CONSULT_1)
					&&StringUtils.isNotBlank(id)
					&&bscInfoVO.getBuOrgCd().equals(PrjBscInfoConstant.CODE_BU_ORG_CD_ZK)
					&&prjQuatPrpsFeeVO.getFeeAmt()>0){
				if(!(StringUtils.isNotBlank(bscInfoVO.getInsCode())&&bscInfoVO.getInsCode().equals(PrjBscInfoConstant.PRJ_INS_CODE_ICBC))){
					throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"请删除方案重新报价!");
				}
			}*/
				if(null==prjQuatPrpsFeeVO.getFeeAmt()){
					logger.info("费用项金额不能为空 prjid:{} ,费用项对象:{} " , prjId , JSON.toJSONString(prjQuatPrpsFeeVO));
					throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"费用项金额不能为空!");
				}
				if(null==prjQuatPrpsFeeVO.getIsFixedAmt()){
					throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"是否为固定金额选项不能为空!");
				}
				if(StringUtils.isEmpty(prjQuatPrpsFeeVO.getCntWayCd())){
					throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"费用项计入方式不能为空!");
				}

				if(null==(prjQuatPrpsFeeVO.getFeePct())&&prjQuatPrpsFeeVO.getIsFixedAmt()==BaseConstant.IS_YESNO_NO){
					throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"固定金额为否，费用比例项不能为空!");
				}
			prjQuatPrpsFeeVO.setFeeAmt(DecimalUtils.convertYuanToFen(prjQuatPrpsFeeVO.getFeeAmt()).doubleValue());//保存到分
		}
		// 兴邦金租二手车交易贷客户保证金比例只能是0-25%的整数
		if(PrjBscInfoConstant.PRJ_INS_CODE_XBFL.equals(bscInfoVO.getInsCode()) && PrjBscInfoConstant.PRJ_TYP_CD_ESCJYD.equals(bscInfoVO.getPrjTypCd())
				&& (collateralPct < 0 || collateralPct > 25 || collateralPct*10%10 != 0)){
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_604_NAME,"客户保证金比例只能是0-25之间的整数(含0和25)");
		}
		//传统城配 非低息业务 判断irr和客户保证金比例判断是否弹窗提示用户修改报价方案
		if(PrjBscInfoConstant.CODE_BU_ORG_CD_ZK.equals(buOrgCd) && (prjTypCd.equals(PrjBscInfoConstant.PRJ_TYP_CD_CPYW) || prjTypCd.equals(PrjBscInfoConstant.PRJ_TYP_CD_CTYW))){
			if(bscInfoVO.getInsCode() != null){
				SysDictionaryDTO sysDictionaryDTO = sysDictionaryApiService.getEntityByPriKey("11000", "0000", DictionaryConstant.CODE_IS_LOWRATE_INS_CD, bscInfoVO.getInsCode());
				if(sysDictionaryDTO != null && !PrjQuatPrpsConstant.SPECIAL_BUSINESS_TYPE_3.equals(specialBusinessType) && "0".equals(prjQuatPrps.getIsNeedOpenWin()) && collateralPct >= 30){
					throw new BaseException("000000", "该项目支持保证金抵租金流程，是否使用？（特殊业务类型需包含低息业务）");
				}
			}else{
				if(!PrjQuatPrpsConstant.SPECIAL_BUSINESS_TYPE_3.equals(specialBusinessType) && "0".equals(prjQuatPrps.getIsNeedOpenWin()) && collateralPct >= 30){
					throw new BaseException("000000", "该项目支持保证金抵租金流程，是否使用？（特殊业务类型需包含低息业务）");
				}
			}
		}
		PrjPrdBscInfoQueryCondition qc = new PrjPrdBscInfoQueryCondition();
		qc.setPrjId(Long.valueOf(prjQuatPrps.getPrjId()));
		List<PrjPrdBscInfoVO> prjprdList = this.prjPrdBscInfoService.searchList(qc);
		if(CollectionUtils.isEmpty(prjprdList)){
			throw new BaseException("项目产品为空");
		}
		String splMfrNm = prjprdList.get(0).getSplMfrNm();
		if(!fee63 && (PrjMfrPrdPaySchMConstant.SPECIAL_MFR_NM_01.equals(splMfrNm)||PrjMfrPrdPaySchMConstant.SPECIAL_MFR_NM_02.equals(splMfrNm)) && bscInfoVO.getIsSplMfr().longValue() == 1l){
			throw new BaseException("发票金额必须大于0");
		}
		//REQ-11719如果是重卡且低息业务，判断保证金比例是否大于半分之三十
		if(PrjQuatPrpsConstant.SPECIAL_BUSINESS_TYPE_3.equals(specialBusinessType) && PrjBscInfoConstant.CODE_BU_ORG_CD_ZK.equals(buOrgCd)){
			if(collateralPct < 30){
				throw new BaseException("低息业务保证金比例低于30%，不满足要求，请重新调整");
			}
		}
		if(!PrjQuatPrpsConstant.SPECIAL_BUSINESS_TYPE_3.equals(specialBusinessType) && "1".equals(isLowBiz)){
			throw new BaseException("所选特殊业务类型不支持此业务（低息），请重新调整");
		}
		//  TODO 浦发 记录费用项 是否为空
		if( StringUtils.isNotEmpty(bscInfoVO.getInsCode())&& bscInfoVO.getInsCode().equals(PrjBscInfoConstant.PRJ_INS_CODE_SPD)){
			/**
			 * REQ-12024 需求，浦发保险费现在 只有包保险 3  或者 包购置税和保险的时候 校验必填保险费
			 */
			if(StringUtils.isNotEmpty(isBp) && ("1".equals(isBp) || "3".equals(isBp) )){
				if(!spdFeeMap.get(PrjQuatPrpsFeeConstant.FEE_TYP_CD_67)){
					throw new BaseException("费用项保险费，不能为空!");
				}
			}
			if(StringUtils.isNotEmpty(isBp) && ("2".equals(isBp) || "3".equals(isBp) )){
				if(!spdFeeMap.get(PrjQuatPrpsFeeConstant.FEE_TYP_CD_67)){
					throw new BaseException("费用项保险费，不能为空!");
				}
			}
		}
		// 安鹏金租参数校验
		if(StringUtils.isNotEmpty(bscInfoVO.getInsCode()) && bscInfoVO.getInsCode().equals(PrjBscInfoConstant.PRJ_INS_CODE_APFL)){
			if (collateralPct != 0d && collateralPct != 5d && collateralPct != 10d && collateralPct != 15d){
				throw new BaseException("客户保证金只支持0,5%,10%,15%") ;
			}
			if (StringUtils.isNotEmpty(annIntRatePct) && (Double.valueOf(annIntRatePct) < 6d || Double.valueOf(annIntRatePct) > 24d) || Double.valueOf(annIntRatePct)*10%5 != 0){
				throw new BaseException("年利率只支持6%~24%,且只能是0.5%的整数倍") ;
			}
		}
        if(StringUtils.isNotEmpty(bscInfoVO.getInsCode())&& bscInfoVO.getInsCode().equals(PrjBscInfoConstant.PRJ_INS_CODE_SHNS)){
            if(!spdFeeMap.get(PrjQuatPrpsFeeConstant.FEE_TYP_CD_30)){
                throw new BaseException("费用项购置税，不能为空!");
            }
            if(!spdFeeMap.get(PrjQuatPrpsFeeConstant.FEE_TYP_CD_67)){
                throw new BaseException("费用项保险费，不能为空!");
            }
        }



		if(ghBackAmt>backAmt){
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"工行返利金额不能大于返利金额的值!");
		}
		if(bscInfoVO.getBuOrgCd().equals(PrjBscInfoConstant.CODE_BU_ORG_CD_ZK)
		  &&StringUtils.isNotBlank(bscInfoVO.getInsCode())
		  &&bscInfoVO.getInsCode().equals(PrjBscInfoConstant.PRJ_INS_CODE_ICBC)){
			if(StringUtils.isBlank(lsPd2)&&null!=bscInfoVO.getIsHaveQuat()&&bscInfoVO.getIsHaveQuat()== BaseConstant.IS_YESNO_YES){
				throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"上装租赁期数不能为空!");
			}
			double pct = (0.2+consltPct/100)/(1+consltPct/100)*100;
			//向上取整
			pct = Math.floor(DecimalUtils.div(pct, 10));
			if(firstPct<pct){
				throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"工行首付比例不能小于"+pct*10+"!");
			}
		}
        if(bscInfoVO.getBuOrgCd().equals(PrjBscInfoConstant.CODE_BU_ORG_CD_XNY)){
            if(bscInfoVO.getBizTypCd().equals(PrjBscInfoConstant.PRJ_BIZ_TYP_CD_JYXZL)&&StringUtils.isBlank(lsPd2)){
                throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "新能源经营性业务请填写期数2！");
            }
        }
		if(bscInfoVO.getBuOrgCd().equals(PrjBscInfoConstant.CODE_BU_ORG_CD_ZK) &&StringUtils.isNotBlank(bscInfoVO.getPrjTypCd())&&((bscInfoVO.getPrjTypCd().equals(PrjBscInfoConstant.PRJ_TYP_CD_CPYW) && (bscInfoVO.getIsSplMfr() == 1L)) || (bscInfoVO.getPrjTypCd().equals(PrjBscInfoConstant.PRJ_TYP_CD_CTYW) && (bscInfoVO.getIsSplMfr() == 1L)))&&flag==false){
			PrjQuatPrpsFeeVO feeVO = new PrjQuatPrpsFeeVO();
			feeVO.setFeePct(Double.valueOf(mfrDiscountRate));
			feeVO.setCntWayCd(PrjQuatPrpsConstant.CODE_PRJ_QUAT_CNT_WAY_OTH);
			feeVO.setFeeTypCd(PrjQuatPrpsFeeConstant.FEE_TYP_CD_54);
			feeVO.setIsFixedAmt(BaseConstant.IS_YESNO_YES);
			feeVO.setFeeAmt(0d);
			feeVO.setIsDel(BaseConstant.IS_YESNO_NO);
			feeVO.setIsSysDef(BaseConstant.IS_YESNO_NO);
			list.add(feeVO);
		}
		//重卡除（工行、厂商业务）之外验证供应商返利与销售返利不能大于融资额的一定比例
        double totalBackAmt = salBack+splBack;
        double actAmt = 0d;
        if(StringUtils.isNotBlank(actLsAmt)){
            actAmt = Double.valueOf(actLsAmt);
        }
        if((bscInfoVO.getBuOrgCd().equals(PrjBscInfoConstant.CODE_BU_ORG_CD_YC))){
            if(totalBackAmt/actAmt>0.05){
                throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"返利总计已超上限，请调整！");
            }
        }

		if(prjQuatPrps.getPayWayCd().equals(PrjQuatPrpsConstant.CODE_BEGI_NO_EQUAL)||prjQuatPrps.getPayWayCd().equals(PrjQuatPrpsConstant.CODE_END_NO_EQUAL)){
			int count = 0;
			if(CollectionUtils.isNotEmpty(prjprdList)){
				for (PrjPrdBscInfoVO prjPrdBscInfoVO : prjprdList) {
					count += prjPrdBscInfoVO.getPrdQty();
				}
			}
			if(count>1){
				throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"不等额支付方式，不支持多台设备!");
			}
		}

		for (PrjQuatPrpsFeeVO prjQuatPrpsFeeVO : contFeeList) {
			if(null==prjQuatPrpsFeeVO.getFeeAmt()){
				prjQuatPrpsFeeVO.setFeeAmt(0d);
			}else{
				prjQuatPrpsFeeVO.setFeeAmt(DecimalUtils.convertYuanToFen(prjQuatPrpsFeeVO.getFeeAmt()).doubleValue());//保存到分
			}
	      }
		List<PrjQuatPrpsPaySchVO> feePayList = new ArrayList<PrjQuatPrpsPaySchVO>();
		if (StringUtils.isNotBlank(payList)) {
			feePayList = JSON.parseArray(payList, PrjQuatPrpsPaySchVO.class);
		}
		for (PrjQuatPrpsPaySchVO prjQuatPrpsPaySchVO : feePayList) {
			prjQuatPrpsPaySchVO.setIntAmt(DecimalUtils.convertYuanToFen(prjQuatPrpsPaySchVO.getIntAmt()).doubleValue());
			prjQuatPrpsPaySchVO.setPrinAmt(DecimalUtils.convertYuanToFen(prjQuatPrpsPaySchVO.getPrinAmt()).doubleValue());
			prjQuatPrpsPaySchVO.setRemPrinAmt(DecimalUtils.convertYuanToFen(prjQuatPrpsPaySchVO.getRemPrinAmt()).doubleValue());
			prjQuatPrpsPaySchVO.setRntAmt(DecimalUtils.convertYuanToFen(prjQuatPrpsPaySchVO.getRntAmt()).doubleValue());
		}
		list.addAll(contFeeList);
		prjQuatPrps.setPrjQuatPrpsPaySchList(feePayList);
		prjQuatPrps.setPrjQuatPrpsFeelist(list);
		//长城金租添加校验
        if(StringUtils.isNotBlank(bscInfoVO.getInsCode())&&bscInfoVO.getInsCode().equals(PrjBscInfoConstant.PRJ_INS_CODE_CCFL)){
            this.prjQuatPrpsService.checkCCFYPrjQuatPrps(prjQuatPrps);
        }
        //三井住友验证
        if(StringUtils.isNotBlank(bscInfoVO.getInsCode())&&bscInfoVO.getInsCode().equals(PrjBscInfoConstant.PRJ_INS_CODE_SMBC)){
            if(prjQuatPrps.getLsPd().intValue()>36){
                throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"期限不符合要求！期数范围[1-36]");
            }
        }
		/**
		 * 兴邦金租添加校验
		 */
		if(StringUtils.isNotBlank(bscInfoVO.getInsCode())&&bscInfoVO.getInsCode().equals(PrjBscInfoConstant.PRJ_INS_CODE_XBFL)
                && (PrjBscInfoConstant.PRJ_TYP_CD_CTYW.equals(bscInfoVO.getPrjTypCd())
                || PrjBscInfoConstant.PRJ_TYP_CD_CPYW.equals(bscInfoVO.getPrjTypCd())
        )){
			prjQuatPrps = this.prjQuatPrpsService.checkZGXBFLPrjQuatPrps(prjQuatPrps);
		}
		if(StringUtils.isNotBlank(bscInfoVO.getInsCode())&&bscInfoVO.getInsCode().equals(PrjBscInfoConstant.PRJ_INS_CODE_XYFL)){
			if(StringUtils.isEmpty(isBp)){
				prjQuatPrps.setIsBp(0);
			}
		}
        //重卡车抵贷业务调整首期比例、金额值  =======================
        if(bscInfoVO.getBuOrgCd().equals(PrjBscInfoConstant.CODE_BU_ORG_CD_ZK)&&(bscInfoVO.getPrjTypCd().equals(PrjBscInfoConstant.PRJ_TYP_CD_CDDYWUL)||bscInfoVO.getPrjTypCd().equals(PrjBscInfoConstant.PRJ_TYP_CD_ESCJYD)
            || PrjBscInfoConstant.PRJ_TYP_CD_OWNJYD.equals(bscInfoVO.getPrjTypCd()))) {
            if(StringUtils.isNotBlank(bscInfoVO.getInsCode())){
            	if(bscInfoVO.getInsCode().equals(PrjBscInfoConstant.PRJ_INS_CODE_JXFL)){
					if(Double.valueOf(annIntRatePct) < 6.5 || Double.valueOf(annIntRatePct) > 23.99 ){
						throw new BaseException("年利率不不符合要求6.5%～23.99%，请重新调整");
					}
					if(bscInfoVO.getPrjTypCd().equals(PrjBscInfoConstant.PRJ_TYP_CD_ESCJYD) || PrjBscInfoConstant.PRJ_TYP_CD_OWNJYD.equals(bscInfoVO.getPrjTypCd())){
						if((firstPct + collateralPct) < 15){
							throw new BaseException("首付比例+保证金比例低于15%，不满足江西金租业务要求，请重新调整");
						}
					}
				}
			}
            if(StringUtils.isBlank(bscInfoVO.getInsCode())
					|| bscInfoVO.getInsCode().equals(PrjBscInfoConstant.PRJ_INS_CODE_JXFL)
					|| bscInfoVO.getInsCode().equals(PrjBscInfoConstant.PRJ_INS_CODE_SYFL)
					|| bscInfoVO.getInsCode().equals(PrjBscInfoConstant.PRJ_INS_CODE_XYFL)) {
            	if(bscInfoVO.getPrjTypCd().equals(PrjBscInfoConstant.PRJ_TYP_CD_CDDYWUL)){
					//车抵贷重新设置首期金额
					double totalCstFina = 0d;//车辆客户融资额合计
					double firstAmt = 0d;//首期金额
					PrjPrdBscInfoQueryCondition prjPrdBscInfoQueryCondition = new PrjPrdBscInfoQueryCondition();
					prjPrdBscInfoQueryCondition.setPrjId(prjQuatPrps.getPrjId());
					List<PrjPrdBscInfoVO> prjPrdBscInfoDTOList =   this.prjPrdBscInfoService.searchList(prjPrdBscInfoQueryCondition);
					if(CollectionUtils.isNotEmpty(prjPrdBscInfoDTOList)){
						for(PrjPrdBscInfoVO prjPrdBscInfoDTO:prjPrdBscInfoDTOList){
							totalCstFina+=DecimalUtils.convertYuanToFen(prjPrdBscInfoDTO.getCustFina()).doubleValue();
						}
					}
					firstAmt =  prjQuatPrps.getContAmt()-totalCstFina;
					for (PrjQuatPrpsFeeVO firstDetail : prjQuatPrps.getPrjQuatPrpsFeelist()) {
						if(firstDetail.getFeeTypCd().equals(PrjQuatPrpsFeeConstant.PRJ_FEE_TYP_FIRST_PRC)){
							firstDetail.setFeeAmt(firstAmt);
							double pct = ProjectUtils.getPctByAmt(prjQuatPrps.getTotLsItmAmt(), prjQuatPrps.getContAmt(), 0d, firstDetail.getCalBaseCd(), firstAmt);
							firstDetail.setFeePct(pct);
							break;
						}
					}
				}
			}
        }

		return prjQuatPrps;
	}

	/**
	 * 修改
	 */
	@RequestMapping(value = "/modify.do", method = { RequestMethod.POST })
	@ResponseBody
	public Object modify(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String id = request.getParameter("id");
		String name = request.getParameter("name");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_UPDATE_SUCC);
		if(StringUtils.isEmpty(id)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
			logger.info("修改报价方案失败,id为空");
			return result;
		}
		PrjQuatPrpsVO entity = null;
		try {
			entity = new PrjQuatPrpsVO();
			entity.setId(Long.valueOf(id));
			//entity.setName(name);
			//TODO ADD PARAM
			boolean success = this.prjQuatPrpsService.modify(entity);
			if(!success){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
				logger.info("修改报价方案失败");
			}
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			logger.error("修改报价方案失败msg:{}",ex.getMessage());
		}catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			logger.error("修改报价方案失败msg:{}",ex.getMessage());
		}
		return result;
	}
	
	/**
	 * 得到一条记录
	 * 
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/checkMultiStepStatus.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object checkMultiStepStatus(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String payPd = request.getParameter("payPd");//租赁期数
		String prjId = request.getParameter("prjId");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_OPERATE_SUCC);
		if(StringUtils.isEmpty(payPd)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
			logger.info("检查是否可以选择阶梯价支付方式失败,期次为空");
			return result;
		}
		
		try {
			PrjBscInfoVO prjBscInfoVO = this.prjBscInfoService.selectById(Long.valueOf(prjId));
			boolean  flag = this.prjQuatPrpsService.checkMultiStepStatus(Integer.valueOf(payPd),prjBscInfoVO.getCstMgrOrgCd());
			if(flag){
				result.setSuccess(BaseConstant.IS_YESNO_YES);
			}else{
				result.setSuccess(BaseConstant.IS_YESNO_NO);
			}
		}catch(BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
		}catch(Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
		}
		return result;
	}
/*	*//**
	 * 拆分报价版支付表信息
	 *//*
	@RequestMapping(value = "/splitQuatPaySch.do", method = { RequestMethod.POST })
	@ResponseBody
	public Object splitQuatPaySch(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String quatId = request.getParameter("id");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_ADD_SUCC);
		Long id  =	 null;
		try {
			if(StringUtils.isBlank(quatId)){
				throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"报价方案ID不能为空!");
			}
			this.prjQuatPrpsService.splitQuatPaySch(Long.valueOf(quatId));
			result.setData(id);
			BaseLogUtils.info(logger, "add", "拆分数据.[id="+id+"] DATA:" + JSONObject.toJSONString(quatId), CurrentThreadContext.getCurrentUserName());
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.info(logger, "add", "拆分数据失败.DATA:" + JSONObject.toJSONString(quatId) + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			BaseLogUtils.error(logger, "add", "拆分数据失败.DATA:" + JSONObject.toJSONString(quatId) + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}

		return result;
	}*/
	
	
	/**
	 * 生成支付表及入录版数据
	 */
	@RequestMapping(value = "/genNomalPaySch.do", method = { RequestMethod.POST })
	@ResponseBody
	public Object genNomalPaySch(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String quatId = request.getParameter("id");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_ADD_SUCC);
		Long id  =	 null;
		try {
			if(StringUtils.isBlank(quatId)){
				throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"报价方案ID不能为空!");
			}
			//this.prjQuatPrpsService.modifyGenNomalPaySch(Long.valueOf(quatId));
			result.setData(quatId);
			logger.info("生成支付表及入录版数据");
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			logger.error("生成录入版失败quatId:{},msg:{}",quatId,ex.getMessage());
		}catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			logger.error("生成录入版失败quatId:{},msg:{}",quatId,ex.getMessage());
		}

		return result;
	}
	
	/**
	 * 删除数据
	 */
	@RequestMapping(value = "/removeByPrjId.do", method = {RequestMethod.POST })
	@ResponseBody
	public DataResultVO removeByPrjId(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String prjId = request.getParameter("prjId");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_DELETE_SUCC);
		if(StringUtils.isEmpty(prjId)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
			return result;
		}
		try {
			this.prjQuatPrpsService.removePrjQuatByPrjId(Long.valueOf(prjId),CurrentThreadContext.getCurrentUserId());
			logger.info("删除报价方案prjId:{}",prjId);
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			logger.error("删除报价方案失败，msg:{}",ex.getMessage());
		}catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			logger.error("删除报价方案失败prjId:{}",prjId);
		}
		return result;
	}
	
	/**
	 * 新增
	 */
	@RequestMapping(value = "/addQuatPrps.do", method = { RequestMethod.POST })
	@ResponseBody
	public Object addQuatPrps(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String quatId = request.getParameter("id");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_ADD_SUCC);
		PrjQuatPrpsVO prjQuatPrps = null;
		Long id  =	 null;
		try {
			// 不还款处理方式（PRJ0015） 暂且借用此字段 做为判断是否使用新报价方法逻辑  测试后去掉
			String noPayWayCd = request.getParameter("noPayWayCd");
			prjQuatPrps = getRequestParams(request);
			// 校验报价方案填写信息是否合规
			addQuatPrpsBeforeValidate(prjQuatPrps);
			prjQuatPrps.setNoPayWayCd(noPayWayCd);
			double firstPct = 0d; // 首期款
			double splitPct = prjQuatPrps.getQuatSplitPct();
			PrjBscInfoVO prjBscInfoVO = prjBscInfoService.selectById(prjQuatPrps.getPrjId());
			//REQ-14253取消
			/*if(prjBscInfoVO != null && prjBscInfoVO.getIsInsBiz() == 0 && "1".equals(prjBscInfoVO.getCompensatoryType())){
				throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"代偿担保业务暂仅支持资管业务，请重新核对");
			}*/
			//如果首付比拆分比例小，重新设置拆分比例
			List<PrjQuatPrpsFeeVO>  feeList = prjQuatPrps.getPrjQuatPrpsFeelist();
			if(CollectionUtils.isNotEmpty(feeList)){
				Double fee117 = 0d,fee118 = 0d ;
				for (PrjQuatPrpsFeeVO prjQuatPrpsFeeVO : feeList) {
					if(prjQuatPrpsFeeVO.getFeeTypCd().equals(PrjQuatPrpsFeeConstant.PRJ_FEE_TYP_FIRST_PRC)  && prjBscInfoVO.getBuOrgCd().equals(PrjBscInfoConstant.CODE_BU_ORG_CD_ZK)){
						if((prjBscInfoVO.getPrjTypCd().equals(PrjBscInfoConstant.PRJ_TYP_CD_CPYW) || prjBscInfoVO.getPrjTypCd().equals(PrjBscInfoConstant.PRJ_TYP_CD_CTYW))
								&& BaseConstant.IS_YESNO_NO == prjBscInfoVO.getIsInsBiz() && prjQuatPrpsFeeVO.getFeePct() < 10d){
							throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"我司项目首期费用比例不能小于10%!");
						}
						if((prjBscInfoVO.getPrjTypCd().equals(PrjBscInfoConstant.PRJ_TYP_CD_CDDYWUL) || prjBscInfoVO.getPrjTypCd().equals(PrjBscInfoConstant.PRJ_TYP_CD_ESCJYD)
                        || PrjBscInfoConstant.PRJ_TYP_CD_OWNJYD.equals(prjBscInfoVO.getPrjTypCd()))
                                && PrjBscInfoConstant.PRJ_INS_CODE_SYFL.equals(prjBscInfoVO.getInsCode()) && prjQuatPrpsFeeVO.getFeePct() < 30d){
                            throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"首期比例不能小于30%!");
                        }
						firstPct = prjQuatPrpsFeeVO.getFeePct();
					}
					if (PrjBscInfoConstant.COMPENSATORY_TYPE_2.equals(prjBscInfoVO.getCompensatoryType())){
						if (PrjQuatPrpsFeeConstant.FEE_TYP_CD_117.equals(prjQuatPrpsFeeVO.getFeeTypCd())){
							fee117 = prjQuatPrpsFeeVO.getFeeAmt() == null?0:prjQuatPrpsFeeVO.getFeeAmt() ;
						}
						if (PrjQuatPrpsFeeConstant.FEE_TYP_CD_118.equals(prjQuatPrpsFeeVO.getFeeTypCd())){
							fee118 = prjQuatPrpsFeeVO.getFeeAmt() == null?0:prjQuatPrpsFeeVO.getFeeAmt() ;
						}
					}
					/*if (prjQuatPrpsFeeVO.getFeeTypCd().equals(PrjQuatPrpsFeeConstant.PRJ_FEE_TYP_PURCHASE)){
						rsrvPcVo = prjQuatPrpsFeeVO.getFeeAmt();
					}*/
				}
				if(prjBscInfoVO.getBuOrgCd().equals(PrjBscInfoConstant.CODE_BU_ORG_CD_ZK)
						&&(prjBscInfoVO.getPrjTypCd().equals(PrjBscInfoConstant.PRJ_TYP_CD_CTYW) || prjBscInfoVO.getPrjTypCd().equals(PrjBscInfoConstant.PRJ_TYP_CD_CPYW))){
					if (fee117 > 0 && fee118 > 0){
						throw new BaseException("担保保证金/垫资保证金不可同时存在") ;
					}
					if (fee117 == 0d && fee118 == 0d && PrjBscInfoConstant.COMPENSATORY_TYPE_2.equals(prjBscInfoVO.getCompensatoryType())){
						throw new BaseException("担保保证金/垫资保证金必须有一项不为0") ;
					}
				} else {
					if (fee117 > 0 || fee118 > 0){
						throw new BaseException("仅重卡新车业务支持担保保证金/垫资保证金") ;
					}
				}
			}
			/*PrjPrdBscInfoQueryCondition prdBscQc = new PrjPrdBscInfoQueryCondition();
			prdBscQc.setPrjId(prjQuatPrps.getPrjId());
			List<PrjPrdBscInfoVO> prjPrdList = this.prjPrdBscInfoService.searchList(prdBscQc);
			if(CollectionUtils.isNotEmpty(prjPrdList)) {
				double rsrvPcToTal = 0d; //项目产品留购价合计
				for (PrjPrdBscInfoVO bscInfoVO : prjPrdList) {
					rsrvPcToTal = rsrvPcToTal + bscInfoVO.getRsrvPc();
				}
				if (prjBscInfoVO.getIsInsBiz() != null && prjBscInfoVO.getIsInsBiz() == BaseConstant.IS_YESNO_YES) {
					if(rsrvPcVo != rsrvPcToTal){
						throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"该资方限制留购价金额（每台）与项目产品留购价金额不一致，请核对！");
					}
				}
			}*/
			// 如果是重卡项目，需计算小贷拿去用额度
			if(prjBscInfoVO.getBuOrgCd().equals(PrjBscInfoConstant.CODE_BU_ORG_CD_ZK)
					&&(prjBscInfoVO.getPrjTypCd().equals(PrjBscInfoConstant.PRJ_TYP_CD_CTYW) || prjBscInfoVO.getPrjTypCd().equals(PrjBscInfoConstant.PRJ_TYP_CD_CPYW))){
				// 获取小贷额度控制开关
				SysCtrlCfgQueryCondition sysCtrlCfgQueryCondition = new SysCtrlCfgQueryCondition();
				sysCtrlCfgQueryCondition.setCtrlCode(PropertiesUtils.getProperty(SysCtrlCfgConstant.SYS_CTRL_CFG_SML_SWITCH_CD));
				sysCtrlCfgQueryCondition.setSysCd(WebBaseConstant.SYS_SYS_CD);
				sysCtrlCfgQueryCondition.setOrgCd(WebBaseConstant.SYS_P_ORG_CD);
				String ctrlCode = this.sysCtrlCfgApiService.searchSysCtrlCfgByCtrlCode(sysCtrlCfgQueryCondition);
				// 获取小贷拿去用额度计算推送子开关
				List<SysDictionaryDTO> smallLoanExceptedList = sysDictionaryApiService.searchGroup(CurrentThreadContext.getCurrentSysCd(), prjBscInfoVO.getCstMgrOrgCd(), PrjQuatPrpsConstant.CODE_GRP_SMALLLOAN_SWITCH);
				Boolean onOff = true ;
				for (SysDictionaryDTO sysDictionaryDTO:smallLoanExceptedList){
					if(prjBscInfoVO.getCstMgrOrgCd().startsWith(sysDictionaryDTO.getCode())){
						onOff = true ;
						break ;
					}
					onOff = false ;
				}
				logger.info("总开关："+ctrlCode + "子开关：" + JSON.toJSONString(smallLoanExceptedList));
				if ("1".equals(ctrlCode) && onOff){
					Double smallAmt =0d;
					BaseParamDTO baseParamDto = new BaseParamDTO();
					baseParamDto.setSysCd(WebBaseConstant.SYS_SYS_CD);
					baseParamDto.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD);
					baseParamDto.setServiceCd(WebBaseConstant.FL_SERVICE_SYS_CD);
					logger.info("查询用户等级和经销商星级RcCstBscInfoId:{},baseParamDto:{}",prjBscInfoVO.getRcCstBscInfoId()==null?"":prjBscInfoVO.getRcCstBscInfoId().toString(),JSON.toJSONString(baseParamDto));
					DataResultDTO rskResult = externalRcCstBscInfoSearchApiService.getRcRskLvlAndSplStarLevel(prjBscInfoVO.getRcCstBscInfoId(), baseParamDto);
					logger.info("查询用户等级和经销商星级rskResult:{}",JSON.toJSONString(rskResult));
					if (rskResult != null && rskResult.getData() != null){
						RcRskLvlAndSplStarResult lv = (RcRskLvlAndSplStarResult)rskResult.getData();
						smallAmt = prjPayInfoForSmallLoanService.calculateSmallAmt(lv.getRskLvlCd2(), lv.getSplStarLevel(), prjQuatPrps.getTotLsItmAmt(), firstPct);
						if(prjQuatPrps.getIsBp() != null && prjQuatPrps.getIsBp()==1){
							Double temp = smallAmt-prjQuatPrps.getTotLsItmAmt()*0.06*(1-firstPct/100);
							smallAmt=temp>0?temp:0;
						}else if(prjQuatPrps.getIsBp() != null && prjQuatPrps.getIsBp()==2){
							smallAmt=0d;
						}
					}
					if(smallAmt > 0 && (prjQuatPrps.getIsLowDownPayment() == null ||
							(!BaseConstant.IS_YESNO_YES_STR.equals(prjQuatPrps.getIsLowDownPayment().toString())
									&& !BaseConstant.IS_YESNO_NO_STR.equals(prjQuatPrps.getIsLowDownPayment().toString())))){
						Map data = new HashMap();
						data.put("code",10000);
						data.put("smallLoanAmt",DecimalUtils.convertFenToYuan(smallAmt.longValue()));
						data.put("msg","您享有拿去用额度，请选择是否使用专享额度产品");
						result.setData(data);
						return result ;
					}
					if (smallAmt > 0){
						prjQuatPrps.setSmallLoanAmt(smallAmt);
					}
				}else{
					prjQuatPrps.setSmallLoanAmt(0d);
				}
			}
			logger.info("addQuatPrps.do保存方案.调用资管路由请求参数prjQuatPrpsprjQuatPrps:{}",JSON.toJSONString(prjQuatPrps));
			DataResultDTO resultDTO = this.insRouteBscInfoService.routeResPrps(prjQuatPrps, BaseConstant.IS_YESNO_YES);
			logger.info("addQuatPrps.do保存方案.调用资管路由返回结果resultDTO:{}",JSON.toJSONString(resultDTO));
            prjQuatPrps.setIsShowIns(BaseConstant.IS_YESNO_NO);
            Long sumFee76 = 0l;
			Long fee76 = 0l;
			Long oriMediationFeeAmt = 0l;
            if(resultDTO!=null){
            	if(BaseConstant.IS_YESNO_NO == resultDTO.getSuccess()){
					JSONObject resObj = (JSONObject)resultDTO.getData();
					prjQuatPrps.setIsCheckRouteFlag(Integer.valueOf(resObj.get("isCheckRouteFlag").toString()));
					prjQuatPrps.setIsShowIns(BaseConstant.IS_YESNO_YES);
					prjQuatPrps.setIsAllowNonIns(Integer.valueOf(resObj.get("isAllowNonIns").toString()));
					prjQuatPrps.setGctInsResList((List<InsRouteInsResVO>)resObj.get("gctInsResList"));
					prjQuatPrps.setUngctInsResList((List<InsRouteInsResVO>)resObj.get("ungctInsResList"));
					logger.info("addQuatPrps.do保存方案.返回结果prjQuatPrpsprjQuatPrps:{}",JSON.toJSONString(prjQuatPrps));
					ListPageVO<PrjQuatPrpsPaySchVO> listPage = new ListPageVO<PrjQuatPrpsPaySchVO>(prjQuatPrps.getPrjQuatPrpsPaySchList(),prjQuatPrps.getPrjQuatPrpsPaySchList().size());
					prjQuatPrps.setPrjQuatPrpsPaySchPage(listPage);
					result.setData(prjQuatPrps);
					return result;
				}else{
					if(resultDTO.getData() != null){
						JSONObject resObj = (JSONObject)resultDTO.getData();
						if(resObj.get("sumFee76") != null){
							sumFee76 = Long.valueOf(resObj.get("sumFee76").toString());
						}
						if(resObj.get("fee76") != null){
							fee76 = Long.valueOf(resObj.get("fee76").toString());
						}
						if(resObj.get("oriMediationFeeAmt") != null){
							oriMediationFeeAmt = Long.valueOf(resObj.get("oriMediationFeeAmt").toString());
						}
					}
				}
            }
			/*if(sumFee76<0){
				nowFee76 = fee76;
			}
			sumFee76 = nowFee76 - oriMediationFeeAmt;
			prjQuatPrps.setContAmt(prjQuatPrps.getContAmt() - oriMediationFeeAmt + nowFee76);
			prjQuatPrps.setTotLsItmAmt(prjQuatPrps.getTotLsItmAmt() - oriMediationFeeAmt + nowFee76);
			for (PrjQuatPrpsFeeVO prjQuatPrpsFeeVO : feeList) {
				String feeTypCd = prjQuatPrpsFeeVO.getFeeTypCd();
				if(PrjQuatPrpsFeeConstant.FEE_TYP_CD_01.equals(feeTypCd)){
					prjQuatPrpsFeeVO.setFeeAmt(prjQuatPrpsFeeVO.getFeeAmt() - oriMediationFeeAmt + nowFee76);
					prjQuatPrpsFeeVO.setFeePct(DecimalUtils.div(prjQuatPrpsFeeVO.getFeeAmt(),prjQuatPrps.getContAmt(),10)*100);
				}
				if(PrjQuatPrpsFeeConstant.FEE_TYP_CD_76.equals(feeTypCd)){
					prjQuatPrpsFeeVO.setFeeAmt(Double.valueOf(nowFee76));
				}
			}
			prjQuatPrps.setPrjQuatPrpsFeelist(feeList);*/
			/**
			 * 同步路由，产品数据
			 */
			/*this.insRouteBscInfoService.synchroInfo(prjBscInfoVO.getId(),sumFee76,CurrentThreadContext.getCurrentUserId());*/
			if(firstPct<=splitPct){
				prjQuatPrps.setQuatSplitPct(firstPct);
			}
			if(StringUtils.isNotBlank(quatId)){
				prjQuatPrps.setId(Long.valueOf(quatId));
			}
			prjQuatPrps.setMdfTm(new Date());
			prjQuatPrps.setMdfUsrId(CurrentThreadContext.getCurrentUserId());
			prjQuatPrps.setCrtTm(new Date());
			prjQuatPrps.setCrtUsrId(CurrentThreadContext.getCurrentUserId());
			prjQuatPrps.setSysCd(CurrentThreadContext.getCurrentSysCd());
			prjQuatPrps.setOrgCd(prjBscInfoVO.getCstMgrOrgCd());
			// 保存报价方案、支付表信息
			id = this.prjQuatPrpsService.modifyGenPrjQuatPrpsAndPayInfo(prjQuatPrps);
			// 如果是传统/城配，更新是否低息标识
			//REQ-13525改为给客户经理弹窗提示修改
			/*if(prjBscInfoVO.getPrjTypCd().equals(PrjBscInfoConstant.PRJ_TYP_CD_CPYW) || prjBscInfoVO.getPrjTypCd().equals(PrjBscInfoConstant.PRJ_TYP_CD_CTYW)){
				PrjQuatPrpsVO prpsVO = this.prjQuatPrpsService.selectById(id);
				PrjQuatPrpsVO prjQuatPrpsVO = new PrjQuatPrpsVO();
				prjQuatPrpsVO.setPrjId(prjBscInfoVO.getId());
				if (prpsVO.getIrrPct() <= 10 && colLateral >= 30){
					prjQuatPrpsVO.setIsLowBiz(BaseConstant.IS_YESNO_YES);
					prjQuatPrpsService.modifyQuatPrpsByPrjId(prjQuatPrpsVO);
				}else{
					prjQuatPrpsVO.setIsLowBiz(BaseConstant.IS_YESNO_NO);
					prjQuatPrpsService.modifyQuatPrpsByPrjId(prjQuatPrpsVO);
				}
			}*/

			//必须是资管且必须支持厂商
			if (BaseConstant.IS_YESNO_YES == prjBscInfoVO.getIsInsBiz()  &&  BaseConstant.IS_YESNO_YES == prjBscInfoVO.getIsSplMfr()) {
				//立项申请选的机构和厂商报价选的机构模式是否一致
				boolean isDifference  = this.validatorCheckedInsCodeModel(prjBscInfoVO);
				if (!isDifference) {
					throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"资管机构模式与预筛选不一致");
				}
			}
			prjQuatPrps.setId(id);
			result.setData(prjQuatPrps);
			logger.info("addQuatPrps.do保存方案.返回结果prjQuatPrps:{}",JSON.toJSONString(prjQuatPrps));
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			Map<String,Object> map = new HashMap<>(16);
			if(ex.getCode() != null && ex.getCode().equals("000000")){
				map.put("isNeedOpenWin","0");
			}else{
				map.put("isNeedOpenWin","1");
			}
			result.setData(map);
			logger.info("addQuatPrps.do保存方案失败prjQuatPrps:{}",JSON.toJSONString(prjQuatPrps))
					;
		}catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			logger.info("addQuatPrps.do保存方案失败prjQuatPrps:{}",JSON.toJSONString(prjQuatPrps));
		}

		return result;
	}

	/**
	 * 到添加页面
	 */
	@RequestMapping(value = "/toAddCarPage.do", method = { RequestMethod.GET, RequestMethod.POST })
	public ModelAndView toAddCarPage(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String prjId = request.getParameter("prjId");
		String id = request.getParameter("id");
		String detailFlag = request.getParameter("detailFlag");
		ModelAndView view = new ModelAndView("project/prjquatprps/prjQuatPrpsCarAdd");
		String prpsCfgId=request.getParameter("prpsCfgId");
		String prpsTypCd = request.getParameter("prpsTypCd");
		String isLowBiz = request.getParameter("isLowBiz");//是否低息
        view.addObject("isLowBiz",isLowBiz);
		PrjQuatPrpsCfgMVO 	quatPrps = null;
		List<PrjQuatPrpsCfgDVO> list = null;
		double initLsPct = 0d;
		int prdNum = 0;
		double totalPrdAmt=0d;
		double totalRsrvPc = 0d;
		//购置税
		double purchTax = 0d;
		double vehVesTax = 0d;
		double commInsuTax = 0d;
		double insuTotalAmt = 0d;
		Long prjPrdId = null;
		String buOrgCd = "";
		String prjCstMgrOrgCd = "";
		List<PrjPrdBscInfoVO> prdList= null;
		double quatRsrvPc = 0d;//方案配置留购价
		Integer isAllowChg = 1; //留购价是否可编辑
		//专车事业部设置购置税、保险、返利
		PrjBscInfoVO prjBscInfoVO = 	this.prjBscInfoService.selectById(Long.valueOf(prjId));
		String prjTypCd = prjBscInfoVO.getPrjTypCd();
		buOrgCd = prjBscInfoVO.getBuOrgCd();
		if(StringUtils.isNotEmpty(prpsCfgId)){
			quatPrps = 	this.prjQuatPrpsCfgMService.selectById(Long.valueOf(prpsCfgId));
			Pager page = new Pager();
			if(null!=prjBscInfoVO&&prjBscInfoVO.getCstMgrOrgCd().contains(PrjBscInfoConstant.CODE_ORG_CD_YZDG)){
				prjCstMgrOrgCd = PrjBscInfoConstant.CODE_ORG_CD_YZDG;
				try{
				if(CollectionUtils.isNotEmpty(prdList)&&null!=prjPrdId){
					PrjPrdBscInfoVO prjPrdBscInfoVO = 	this.prjPrdBscInfoService.selectPrjPrdBscAndDetailInfoById(prjPrdId.toString());
					PrjPrdExtVO car = prjPrdBscInfoVO.getPrjPrdExtVO();
					double  outVol = 0d;//排量
					//double guidePc = prjPrdBscInfoVO.getGuidePc(); 取产品的指导价信息
					double guidePc =0d;
					if(null!=car&&null!=car.getOutVol()){
						outVol = Double.valueOf(car.getOutVol());
					}
					if(null!=prjPrdBscInfoVO.getPrdId()){
						PrdCarInfoVO	prdCar = this.prdCarInfoService.selectPrdCarById(Long.valueOf(prjPrdBscInfoVO.getPrdDtlId()));
						PrdBscInfoVO prdBsc = prdBscInfoService.selectById(prjPrdBscInfoVO.getPrdId());
						if(null!=prdCar){
							if(null!=prdCar.getGuidePc()){
								guidePc = DecimalUtils.convertFenToYuan(prdCar.getGuidePc());
							}else if(null!=prdBsc.getGuidePc()){
								guidePc = prdBsc.getGuidePcDouble();
							}
						}
					}else{
						throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"请选择项目产品后再报价!");
					}
					//double guidePc = prjPrdBscInfoVO.getGuidePc();
				
					if(outVol<=PrjQuatPrpsConstant.CODE_PRJ_QUAT_PURCH_TAX_BASE1){
						purchTax = DecimalUtils.round(DecimalUtils.mul(DecimalUtils.div(guidePc, PrjQuatPrpsConstant.CODE_PRJ_QUAT_PURCH_TAX_BASE2), PrjQuatPrpsConstant.CODE_PRJ_QUAT_PURCH_TAX_BASE3), 2);
					}
					if(outVol>PrjQuatPrpsConstant.CODE_PRJ_QUAT_PURCH_TAX_BASE1){
						purchTax = DecimalUtils.round(DecimalUtils.div(guidePc, PrjQuatPrpsConstant.CODE_PRJ_QUAT_PURCH_TAX_BASE2), 2);
					}
					double purchTax1 = Math.ceil(purchTax/10);
					purchTax = purchTax1*10;
					List<SysDictionaryDTO> vehVesList =  sysDictionaryApiService.searchGroup(CurrentThreadContext.getCurrentSysCd(), prjBscInfoVO.getCstMgrOrgCd(),PrjQuatPrpsConstant.CODE_VEH_VES_TAX_CD );
					if(CollectionUtils.isNotEmpty(vehVesList)){
						for (SysDictionaryDTO sysDictionaryDTO : vehVesList) {
							if(null!=sysDictionaryDTO.getCodeAttr1()&&null!=sysDictionaryDTO.getCodeAttr2()){
								if(outVol>=Double.valueOf(sysDictionaryDTO.getCodeAttr1())&&outVol<Double.valueOf(sysDictionaryDTO.getCodeAttr2())){
									vehVesTax = DecimalUtils.convertFenToYuan(Long.valueOf(sysDictionaryDTO.getCode()));
								}
							}
							if(null!=sysDictionaryDTO.getCodeAttr1()&&null==sysDictionaryDTO.getCodeAttr2()&&outVol>=Double.valueOf(sysDictionaryDTO.getCodeAttr1())){
								vehVesTax = DecimalUtils.convertFenToYuan(Long.valueOf(sysDictionaryDTO.getCode()));
							}
						}
					}
					Double guidePc1= DecimalUtils.div(guidePc, 10000);
					List<SysDictionaryDTO> commInsuList =  sysDictionaryApiService.searchGroup(CurrentThreadContext.getCurrentSysCd(), prjBscInfoVO.getCstMgrOrgCd(),PrjQuatPrpsConstant.CODE_COMM_INSU_RATE_CD );
					if(CollectionUtils.isNotEmpty(commInsuList)){
						for (SysDictionaryDTO sysDictionaryDTO : commInsuList) {
							if(null!=sysDictionaryDTO.getCodeAttr1()&&null!=sysDictionaryDTO.getCodeAttr2()){
								if(guidePc1>=Double.valueOf(sysDictionaryDTO.getCodeAttr1())&&guidePc1<Double.valueOf(sysDictionaryDTO.getCodeAttr2())){
									commInsuTax = Double.valueOf(sysDictionaryDTO.getCode());
								}
							}
							if(null!=sysDictionaryDTO.getCodeAttr1()&&null==sysDictionaryDTO.getCodeAttr2()&&guidePc1>=Double.valueOf(sysDictionaryDTO.getCodeAttr1())){
								commInsuTax = Double.valueOf(sysDictionaryDTO.getCode());
							}
						}
					}
					insuTotalAmt = PrjQuatPrpsConstant.CODE_COMP_INSU+vehVesTax+DecimalUtils.round(DecimalUtils.mul(guidePc,DecimalUtils.div(commInsuTax, 100)),2);
					
					double insuTotalAmt1 = Math.ceil(insuTotalAmt/10);
					insuTotalAmt = insuTotalAmt1*10;
				}
				initLsPct=  prjQuatPrpsService.getInitLsPct(CurrentThreadContext.getCurrentSysCd(), buOrgCd);
				}catch (BaseException ex) {
						logger.error("跳转到产品信息页面查询异常:msg:{}",ex.getMessage());
				} catch (Exception e) {
						logger.error("跳转到产品信息页面查询异常:msg:{}",e.getMessage());
				}
			}
			PrjQuatPrpsCfgDQueryCondition qc = new PrjQuatPrpsCfgDQueryCondition();
			page.setEveryPage(Integer.MAX_VALUE);//最大数据量
			qc.setPrpsCfgId(Long.valueOf(prpsCfgId));
			page.setCondition(qc);
			Pager pager = this.prjQuatPrpsCfgDService.searchListPage(page);
			list = (List<PrjQuatPrpsCfgDVO>) pager.getResultList();
			logger.info("toAddCarPage方案费用项初始化.路由前结果list:{}",JSON.toJSON(list));
			Integer isInsBiz = prjBscInfoVO.getIsInsBiz();
			if(!(PrjBscInfoConstant.CODE_BU_ORG_CD_XNY.equals(buOrgCd) && !(BaseConstant.IS_YESNO_YES == isInsBiz))){
				InsRouteBscInfoVO insRouteBscInfoVO = this.insRouteBscInfoService.searchListByPrjId(Long.valueOf(prjId));
				logger.info("toAddCarPage获取路由信息.查询路由数据结果insRouteBscInfoVO:{}", JSON.toJSONString(insRouteBscInfoVO));
				List<InsRoutePrpsFeeVO> insRoutePrpsFeeVOList = new ArrayList<InsRoutePrpsFeeVO>();
				if(insRouteBscInfoVO != null){
					quatPrps.setLsPd(insRouteBscInfoVO.getLsPd());
					view.addObject("isBp", insRouteBscInfoVO.getIsBp());//是否包牌
					view.addObject("annIntRatePct", insRouteBscInfoVO.getAnnIntRatePct());//租赁年利率
					insRoutePrpsFeeVOList = insRouteBscInfoVO.getInsRoutePrpsFeeVOList();
				}
				List<InsRoutePrdInfoVO> insRoutePrdInfoVOList = insRouteBscInfoVO.getInsRoutePrdInfoVOList();
				Double mediationFeeAmtSum = 0d;
				if(CollectionUtils.isNotEmpty(insRoutePrdInfoVOList)){
					for (InsRoutePrdInfoVO insRoutePrdInfoVO : insRoutePrdInfoVOList) {
						mediationFeeAmtSum += DecimalUtils.convertFenToYuan(insRoutePrdInfoVO.getMediationFeeAmt()*insRoutePrdInfoVO.getPrdQty());
					}
				}
				Double actAmt = 0d;
				boolean fee76 = false;
				for (PrjQuatPrpsCfgDVO prjQuatPrpsCfgDVO : list) {
					String feeTypCd = prjQuatPrpsCfgDVO.getFeeTypCd();
					//留购价
					if(StringUtils.isNotEmpty(feeTypCd) && PrjQuatPrpsFeeConstant.PRJ_FEE_TYP_PURCHASE.equals(feeTypCd)){
						quatRsrvPc = prjQuatPrpsCfgDVO.getFixedAmt();
						isAllowChg = prjQuatPrpsCfgDVO.getIsAllowChg();
					}
					if(PrjQuatPrpsFeeConstant.FEE_TYP_CD_76.equals(feeTypCd)){
						fee76 = true;
						prjQuatPrpsCfgDVO.setFixedAmt(mediationFeeAmtSum);
						if(PrjBscInfoConstant.PRJ_TYP_CD_CDDYWUL.equals(prjTypCd) || PrjBscInfoConstant.PRJ_TYP_CD_ESCJYD.equals(prjTypCd) || PrjBscInfoConstant.PRJ_TYP_CD_OWNJYD.equals(prjTypCd)){
							prjQuatPrpsCfgDVO.setCntWayCd(PrjQuatPrpsConstant.CODE_PRJ_QUAT_CNT_WAY_CONT);
							prjQuatPrpsCfgDVO.setCntWayCdNm("计入合同额");
							prjQuatPrpsCfgDVO.setIsAllowChg(BaseConstant.IS_YESNO_NO);
						}else{
							prjQuatPrpsCfgDVO.setCntWayCd(PrjQuatPrpsConstant.CODE_PRJ_QUAT_CNT_WAY_OTH);
							prjQuatPrpsCfgDVO.setCntWayCdNm("其他费用");
						}
						prjQuatPrpsCfgDVO.setIsFixedAmt(BaseConstant.IS_YESNO_YES);
						prjQuatPrpsCfgDVO.setIsFixedAmtNm("是");
					}
					if(StringUtils.isNotEmpty(feeTypCd)
							&& (PrjQuatPrpsFeeConstant.FEE_TYP_CD_01.equals(feeTypCd)
							|| PrjQuatPrpsFeeConstant.FEE_TYP_CD_02.equals(feeTypCd)
							|| PrjQuatPrpsFeeConstant.FEE_TYP_CD_63.equals(feeTypCd)
							|| PrjQuatPrpsFeeConstant.FEE_TYP_CD_64.equals(feeTypCd))){
						if(CollectionUtils.isNotEmpty(insRoutePrpsFeeVOList)){
							for (InsRoutePrpsFeeVO insRoutePrpsFeeVO : insRoutePrpsFeeVOList) {
								if(PrjQuatPrpsFeeConstant.FEE_TYP_CD_01.equals(insRoutePrpsFeeVO.getFeeTypCd())){
									actAmt = insRouteBscInfoVO.getContAmt() - insRoutePrpsFeeVO.getFeeAmt();
								}
							}
							for (InsRoutePrpsFeeVO insRoutePrpsFeeVO : insRoutePrpsFeeVOList) {
								if(feeTypCd.equals(insRoutePrpsFeeVO.getFeeTypCd())){
									if(null!=insRoutePrpsFeeVO.getFeeAmt()){
										prjQuatPrpsCfgDVO.setFixedAmt(DecimalUtils.convertFenToYuan(insRoutePrpsFeeVO.getFeeAmt().longValue()));
									}
									if(null!=insRoutePrpsFeeVO.getFeePct() && insRoutePrpsFeeVO.getFeePct().doubleValue() != 0){
										prjQuatPrpsCfgDVO.setFeePct(insRoutePrpsFeeVO.getFeePct());
									}
									if(null!=insRoutePrpsFeeVO.getCntWayCd()){
										prjQuatPrpsCfgDVO.setCntWayCd(insRoutePrpsFeeVO.getCntWayCd());
									}
									if(null!=insRoutePrpsFeeVO.getIsFixedAmt()){
										prjQuatPrpsCfgDVO.setIsFixedAmt(insRoutePrpsFeeVO.getIsFixedAmt());
									}
									if(PrjQuatPrpsFeeConstant.FEE_TYP_CD_02.equals(feeTypCd)){
										if(StringUtils.isNotBlank(insRoutePrpsFeeVO.getCalBaseCd())
												&& !((insRoutePrpsFeeVO.getCalBaseCd()).equals(prjQuatPrpsCfgDVO.getCalBaseCd()))){
											if(PrjQuatPrpsConstant.CODE_CAL_BASE_CONTRACT.equals(prjQuatPrpsCfgDVO.getCalBaseCd())){
												if(null!=insRoutePrpsFeeVO.getFeeAmt()){
													prjQuatPrpsCfgDVO.setFeePct(DecimalUtils.div(insRoutePrpsFeeVO.getFeeAmt(),insRouteBscInfoVO.getContAmt(),10)*100);
												}
											}else if(PrjQuatPrpsConstant.CODE_CAL_BASE_FINANCING.equals(prjQuatPrpsCfgDVO.getCalBaseCd())){
												prjQuatPrpsCfgDVO.setFeePct(DecimalUtils.div(insRoutePrpsFeeVO.getFeeAmt(),actAmt,10)*100);
											}
                                            view.addObject("insRouteInfo", "由于该报价方案客户保证金计算基数与资管路由不一致，系统已重新推算比例值");
										}
									}
								}
							}
						}
					}
				}
				if(mediationFeeAmtSum != 0 && !fee76){
					PrjQuatPrpsCfgDVO prjQuatPrpsCfgDVO = new PrjQuatPrpsCfgDVO();
					prjQuatPrpsCfgDVO.setPrpsCfgId(list.get(0).getPrpsCfgId());
					prjQuatPrpsCfgDVO.setFeeTypCd(PrjQuatPrpsFeeConstant.FEE_TYP_CD_76);
					prjQuatPrpsCfgDVO.setFeeTypCdNm("调节费");
					prjQuatPrpsCfgDVO.setIsAllowChg(BaseConstant.IS_YESNO_YES);
					prjQuatPrpsCfgDVO.setIsAllowChgNm("是");
					prjQuatPrpsCfgDVO.setIsSysDef(BaseConstant.IS_YESNO_NO);
					prjQuatPrpsCfgDVO.setIsSysDefNm("否");
					prjQuatPrpsCfgDVO.setFixedAmt(mediationFeeAmtSum);
					if(PrjBscInfoConstant.PRJ_TYP_CD_CDDYWUL.equals(prjTypCd) || PrjBscInfoConstant.PRJ_TYP_CD_ESCJYD.equals(prjTypCd) || PrjBscInfoConstant.PRJ_TYP_CD_OWNJYD.equals(prjTypCd)){
						prjQuatPrpsCfgDVO.setCntWayCd(PrjQuatPrpsConstant.CODE_PRJ_QUAT_CNT_WAY_CONT);
						prjQuatPrpsCfgDVO.setCntWayCdNm("计入合同额");
						prjQuatPrpsCfgDVO.setIsAllowChg(BaseConstant.IS_YESNO_NO);
					}else{
						prjQuatPrpsCfgDVO.setCntWayCd(PrjQuatPrpsConstant.CODE_PRJ_QUAT_CNT_WAY_OTH);
						prjQuatPrpsCfgDVO.setCntWayCdNm("其他费用");
					}
					prjQuatPrpsCfgDVO.setIsFixedAmt(BaseConstant.IS_YESNO_YES);
					prjQuatPrpsCfgDVO.setIsFixedAmtNm("是");
					list.add(prjQuatPrpsCfgDVO);
				}
			}
		}
		PrjPrdBscInfoQueryCondition prdQc = new PrjPrdBscInfoQueryCondition();
		if(StringUtils.isNotBlank(prjId)){
			prdQc.setPrjId(Long.valueOf(prjId));
			prdList=	this.prjPrdBscInfoService.searchList(prdQc);
			if(CollectionUtils.isNotEmpty(prdList)){
				prjPrdId = prdList.get(0).getId();
				for (PrjPrdBscInfoVO prjPrdBscInfoVO : prdList) {
					//资管项目、报价方案配置留购价不可变更、留购价与项目产品留购价不一致提示校验信息
					if(prjBscInfoVO.getIsInsBiz().equals(BaseConstant.IS_YESNO_YES) && isAllowChg == BaseConstant.IS_YESNO_NO && !prjPrdBscInfoVO.getRsrvPc().equals(quatRsrvPc)){
						throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"该资方要求留购价为固定"+ DecimalUtils.convertFenToYuan(Long.valueOf(String.valueOf(quatRsrvPc))) + "元/台，请在项目产品信息中修改！");
					}
					totalPrdAmt += DecimalUtils.mul(prjPrdBscInfoVO.getGuidePc(), prjPrdBscInfoVO.getPrdQty());
					totalRsrvPc +=DecimalUtils.mul(prjPrdBscInfoVO.getRsrvPc(), prjPrdBscInfoVO.getPrdQty());
					prdNum +=prjPrdBscInfoVO.getPrdQty();
				}
			}
		}
		
		BigDecimal bd = new BigDecimal(totalPrdAmt); 
		String totalPrdAmtStr = bd.toPlainString();
		
		BigDecimal rsrvPc = new BigDecimal(DecimalUtils.convertFenToYuan(new Double(totalRsrvPc).longValue())); 
		String totalRsrvPcStr = rsrvPc.toPlainString();
		//根据id查询修改数据
		if(StringUtils.isNotBlank(id)){
			//查询已经保存的报价方案
			PrjQuatPrpsVO prjQuatPrps = this.prjQuatPrpsService.selectById(Long.valueOf(id));
			ListPageVO<PrjQuatPrpsPaySchVO> payListPage = new ListPageVO<PrjQuatPrpsPaySchVO>(prjQuatPrps.getPrjQuatPrpsPaySchList(),prjQuatPrps.getPrjQuatPrpsPaySchList().size());
			prjQuatPrps.setPrjQuatPrpsPaySchPage(payListPage);
			if(!buOrgCd.equals(PrjBscInfoConstant.CODE_BU_ORG_CD_ZC)){
				if(CollectionUtils.isNotEmpty(prjQuatPrps.getPrjQuatPrpsFeelist())){
					//过滤返利的费用项
					for (int i=0;i<prjQuatPrps.getPrjQuatPrpsFeelist().size(); i++) {
						PrjQuatPrpsFeeVO feeVO = prjQuatPrps.getPrjQuatPrpsFeelist().get(0);
						if(feeVO.getFeeTypCd().equals(PrjQuatPrpsConstant.CODE_FEE_WAY_TYPE_GPS_BACK)||feeVO.getFeeTypCd().equals(PrjQuatPrpsConstant.CODE_FEE_WAY_TYPE_SPL_BACK)){
							prjQuatPrps.getPrjQuatPrpsFeelist().remove(i);
						}
						
					}
				}
			}
			ListPageVO<PrjQuatPrpsFeeVO> detailListPage = new ListPageVO<PrjQuatPrpsFeeVO>(prjQuatPrps.getPrjQuatPrpsFeelist(),prjQuatPrps.getPrjQuatPrpsFeelist().size());
			prjQuatPrps.setPrjQuatPrpsFeePage(detailListPage);
			view.addObject("detailListPage", JSON.toJSONString(detailListPage));
			view.addObject("payListPage", JSON.toJSONString(payListPage));
			view.addObject("prjQuatPrps", JSON.toJSONString(prjQuatPrps));
            view.addObject("cstIrr", prjQuatPrps.getCstIrr());
			prpsTypCd = prjQuatPrps.getPrpsTypCd();
		}
		view.addObject("id", id);
		//租赁期数单位
		List<KeyValueVO> lsPdUntCdList = this.prjQuatPrpsCfgMService.searchLsPdUntCdList();
		view.addObject("lsPdUntCdList", lsPdUntCdList);
		//支付方式
		List<KeyValueVO> payWayCdList = this.prjBscInfoService.getKeyValueList(DictionaryConstant.CODE_PRJ_QUAT_PAY_WAY_CD,CurrentThreadContext.getCurrentSysCd(),prjBscInfoVO.getCstMgrOrgCd());
		/*List<KeyValueVO> payWayCdList = this.prjQuatPrpsCfgMService.searchPayWayCdList();*/
		view.addObject("payWayCdList", payWayCdList);
		//保证金处理方式
		List<KeyValueVO> dpstHdlWayCdList = this.prjQuatPrpsCfgMService.searchDpstHdlWayCdList();
		view.addObject("dpstHdlWayCdList", dpstHdlWayCdList);
		//租赁期满处理方式
		List<KeyValueVO> expHdlWayCdList = this.prjQuatPrpsCfgMService.searchExpHdlWayCdList();
		view.addObject("expHdlWayCdList", expHdlWayCdList);
		//不还款处理方式
		List<KeyValueVO> noPayWayCdList = this.prjBscInfoService.searchNoPayWayCdList();
		view.addObject("noPayWayCdList", noPayWayCdList);
		//费用类型
		JSONArray feeTypCdListJSON = this.prjQuatPrpsCfgMService.searchFeeTypCdList();
		view.addObject("feeTypCdListJSON", feeTypCdListJSON);
		//费用计算基数
		List<KeyValueVO> calBaseCdList = this.prjQuatPrpsCfgMService.searchCalBaseCdList();
		view.addObject("calBaseCdListJSON", JSON.toJSONString(calBaseCdList));
		List<KeyValueVO> yesNoCdList = this.prjQuatPrpsCfgMService.searchYesOrNoCdList();
		view.addObject("yesOrNoCdListJSON",JSON.toJSONString(yesNoCdList) );
		//费用计入方式
		List<KeyValueVO> cntWayCdList = this.prjQuatPrpsCfgMService.searchCntWayCdList();
		//计算方式
		List<KeyValueVO> lsCalWayCdList = this.prjBscInfoService.searchLsCalWayCdList();
		//租赁年利率计算方式
		List<KeyValueVO> intRateWayCdList = this.prjBscInfoService.searchIntRateWayCdList();
		//拆分比例
		List<KeyValueVO> prjQuatSplitPctList = this.prjBscInfoService.getKeyValueList(DictionaryConstant.CODE_QUAT_SPLIT_CD,CurrentThreadContext.getCurrentSysCd(),prjBscInfoVO.getCstMgrOrgCd());
		/*List<KeyValueVO> prjQuatSplitPctList = this.prjBscInfoService.getPrjQuatSplitPctList();*/
		
		//专车客车从咨询费1拆分出来的供应商比例
		List<KeyValueVO> prjConsSplitPctList = this.prjBscInfoService.getPrjConsSplitPctList();
		
		Map<String,String>  scaleNumMap  =  this.prjQuatPrpsService.getDecimalDigitsByBuOrgCodeNew(prjBscInfoVO.getCstMgrOrgCd());
		view.addObject("cntWayCdListJSON", JSON.toJSONString(cntWayCdList));
		view.addObject("prjId", prjId);
		view.addObject("prjConsSplitPctList", JSON.toJSONString(prjConsSplitPctList));
		view.addObject("quatPrps", quatPrps);//配置方案信息
		view.addObject("quatPrpsJson", quatPrps==null?"": JSON.toJSONString(quatPrps));//配置方案信息
		view.addObject("PrjQuatPrpsCfgDetailList", list);//配置明细信息
		view.addObject("lsPdUntCdList", lsPdUntCdList);//租赁期数单位
		view.addObject("payWayCdList", payWayCdList);//支付方式
		view.addObject("lsCalWayCdList", lsCalWayCdList);//计算方式
		view.addObject("calBaseCdList", calBaseCdList);//费用计算基数
		view.addObject("cntWayCdList", cntWayCdList);///费用计入方式
		view.addObject("intRateWayCdList", intRateWayCdList);//租赁年利率计算方式
		view.addObject("dpstHdlWayCdList", dpstHdlWayCdList);//客户保证金处理方式
		view.addObject("expHdlWayCdList", expHdlWayCdList);//租赁期满处理方式
		view.addObject("prdNum", prdNum);//产品数量 
		view.addObject("totalPrdAmt",totalPrdAmtStr);
		/**
		 * 资管机构 兴邦留购价设置为0
		 */
		if(StringUtils.isNotEmpty(prjBscInfoVO.getInsCode()) && prjBscInfoVO.getInsCode().equals(PrjBscInfoConstant.PRJ_INS_CODE_XBFL)){
			totalRsrvPcStr = "0";
		}
		view.addObject("totalRsrvPcStr",totalRsrvPcStr);//留购价总金额
		view.addObject("prjTypCd", null== prjTypCd ?"": prjTypCd);
		view.addObject("detailFlag",detailFlag);
		view.addObject("prpsCfgId", prpsCfgId);
		view.addObject("scaleNumMap", scaleNumMap.isEmpty()==true?"":JSON.toJSONString(scaleNumMap));
		view.addObject("prpsTypCd", prpsTypCd);
		view.addObject("prjQuatSplitPctList", prjQuatSplitPctList);
		view.addObject("insuTotalAmt", insuTotalAmt);
		view.addObject("purchTax", purchTax);
		view.addObject("buOrgCd", buOrgCd);
		view.addObject("initLsPct", initLsPct);
		view.addObject("prjCstMgrOrgCd", prjCstMgrOrgCd);
        view.addObject("insCode",null==prjBscInfoVO.getInsCode()?"":prjBscInfoVO.getInsCode());
		return view;
	}


	/**
	 * 到添加页面
	 */
	@RequestMapping(value = "/toCarDetailPage.do", method = { RequestMethod.GET, RequestMethod.POST })
	public ModelAndView toCarDetailPage(HttpServletRequest request, HttpServletResponse response) {
		String prjId = request.getParameter("prjId");
		String id = request.getParameter("id");
		String detailFlag = request.getParameter("detailFlag");
		ModelAndView view = new ModelAndView("project/prjquatprps/prjQuatPrpsCarDetail");
		String prpsCfgId=request.getParameter("prpsCfgId");
		String prpsTypCd = request.getParameter("prpsTypCd");
		String insCode = request.getParameter("insCode"); //金融结构编码
		String isLowBiz = request.getParameter("isLowBiz");//是否低息
		view.addObject("insCode",insCode);
        view.addObject("isLowBiz",isLowBiz);
		PrjQuatPrpsCfgMVO 	quatPrps = null;
		List<PrjQuatPrpsCfgDVO> list = null;
		PrjBscInfoVO prjBscInfoVO = null;

		int prdNum = 0;
		double totalPrdAmt=0d;
		double totalRsrvPc = 0d;
		if(StringUtils.isNotEmpty(prpsCfgId)){
			quatPrps = 	this.prjQuatPrpsCfgMService.selectById(Long.valueOf(prpsCfgId));
			Pager page = new Pager();

			PrjQuatPrpsCfgDQueryCondition qc = new PrjQuatPrpsCfgDQueryCondition();
			page.setEveryPage(Integer.MAX_VALUE);//最大数据量
			    qc.setPrpsCfgId(Long.valueOf(prpsCfgId));
				page.setCondition(qc);
				Pager pager = this.prjQuatPrpsCfgDService.searchListPage(page);
				list = (List<PrjQuatPrpsCfgDVO>) pager.getResultList();
		}
		PrjPrdBscInfoQueryCondition prdQc = new PrjPrdBscInfoQueryCondition();
		if(StringUtils.isNotBlank(prjId)){
			prdQc.setPrjId(Long.valueOf(prjId));
			List<PrjPrdBscInfoVO> prdList=	this.prjPrdBscInfoService.searchList(prdQc);
			if(CollectionUtils.isNotEmpty(prdList)){
				for (PrjPrdBscInfoVO prjPrdBscInfoVO : prdList) {
					totalPrdAmt += DecimalUtils.mul(prjPrdBscInfoVO.getGuidePc(), prjPrdBscInfoVO.getPrdQty());
					totalRsrvPc +=DecimalUtils.mul(prjPrdBscInfoVO.getRsrvPc(), prjPrdBscInfoVO.getPrdQty());
				}
			}
			//查询信息，获取事业部编码和项目类型
			prjBscInfoVO = this.prjBscInfoService.selectById(Long.valueOf(prjId));
		}
		BigDecimal bd = new BigDecimal(totalPrdAmt); 
		String totalPrdAmtStr = bd.toPlainString();
		
		BigDecimal rsrvPc = new BigDecimal(DecimalUtils.convertFenToYuan(new Double(totalRsrvPc).longValue())); 
		String totalRsrvPcStr = rsrvPc.toPlainString();
		//根据id查询修改数据
		if(StringUtils.isNotBlank(id)){
			//查询已经保存的报价方案
			List<PrjQuatPrpsFeeVO> contFeeVOList =  new ArrayList<PrjQuatPrpsFeeVO>();
			
			PrjQuatPrpsVO prjQuatPrps = this.prjQuatPrpsService.selectById(Long.valueOf(id));
			ListPageVO<PrjQuatPrpsPaySchVO> payListPage = new ListPageVO<PrjQuatPrpsPaySchVO>(prjQuatPrps.getPrjQuatPrpsPaySchList(),prjQuatPrps.getPrjQuatPrpsPaySchList().size());
			prjQuatPrps.setPrjQuatPrpsPaySchPage(payListPage);
			if(CollectionUtils.isEmpty(prjQuatPrps.getPrjQuatPrpsFeelist())){
				for (int i=0; i<prjQuatPrps.getPrjQuatPrpsFeelist().size(); i++) {
					PrjQuatPrpsFeeVO feeVO = prjQuatPrps.getPrjQuatPrpsFeelist().get(i);
					if(feeVO.getCntWayCd().equals(PrjQuatPrpsConstant.CODE_PRJ_QUAT_CNT_WAY_CONT)){
						contFeeVOList.add(feeVO);
					}
					prjQuatPrps.getPrjQuatPrpsFeelist().remove(i);
				}
			}
			
			ListPageVO<PrjQuatPrpsFeeVO> detailListPage = new ListPageVO<PrjQuatPrpsFeeVO>(prjQuatPrps.getPrjQuatPrpsFeelist(),prjQuatPrps.getPrjQuatPrpsFeelist().size());
			prjQuatPrps.setPrjQuatPrpsFeePage(detailListPage);
			ListPageVO<PrjQuatPrpsFeeVO> contFeeVOListPage = new ListPageVO<PrjQuatPrpsFeeVO>(contFeeVOList,contFeeVOList.size());
			view.addObject("contFeeListPage", JSON.toJSONString(contFeeVOListPage));
			view.addObject("detailListPage", JSON.toJSONString(detailListPage));
			view.addObject("payListPage", JSON.toJSONString(payListPage));
			view.addObject("prjQuatPrps", JSON.toJSONString(prjQuatPrps));
            view.addObject("cstIrr", prjQuatPrps.getCstIrr());
			prpsTypCd = prjQuatPrps.getPrpsTypCd();
		}
		view.addObject("id", id);
		//租赁期数单位
		List<KeyValueVO> lsPdUntCdList = this.prjQuatPrpsCfgMService.searchLsPdUntCdList();
		view.addObject("lsPdUntCdList", lsPdUntCdList);
		//支付方式
		List<KeyValueVO> payWayCdList = this.prjQuatPrpsCfgMService.searchPayWayCdList();
		view.addObject("payWayCdList", payWayCdList);
		//保证金处理方式
		List<KeyValueVO> dpstHdlWayCdList = this.prjQuatPrpsCfgMService.searchDpstHdlWayCdList();
		view.addObject("dpstHdlWayCdList", dpstHdlWayCdList);
		//租赁期满处理方式
		List<KeyValueVO> expHdlWayCdList = this.prjQuatPrpsCfgMService.searchExpHdlWayCdList();
		view.addObject("expHdlWayCdList", expHdlWayCdList);
		//不还款处理方式
		List<KeyValueVO> noPayWayCdList = this.prjBscInfoService.searchNoPayWayCdList();
		view.addObject("noPayWayCdList", noPayWayCdList);
		//费用类型
		JSONArray feeTypCdListJSON = this.prjQuatPrpsCfgMService.searchFeeTypCdList();
		view.addObject("feeTypCdListJSON", feeTypCdListJSON);
		//费用计算基数
		List<KeyValueVO> calBaseCdList = this.prjQuatPrpsCfgMService.searchCalBaseCdList();
		view.addObject("calBaseCdListJSON", JSON.toJSONString(calBaseCdList));
		List<KeyValueVO> yesNoCdList = this.prjQuatPrpsCfgMService.searchYesOrNoCdList();
		view.addObject("yesOrNoCdListJSON",JSON.toJSONString(yesNoCdList) );
		//费用计入方式
		List<KeyValueVO> cntWayCdList = this.prjQuatPrpsCfgMService.searchCntWayCdList();
		//计算方式
		List<KeyValueVO> lsCalWayCdList = this.prjBscInfoService.searchLsCalWayCdList();
		//租赁年利率计算方式
		List<KeyValueVO> intRateWayCdList = this.prjBscInfoService.searchIntRateWayCdList();
		//拆分比例
		List<KeyValueVO> prjQuatSplitPctList = this.prjBscInfoService.getPrjQuatSplitPctList();
		Map<String,String>  scaleNumMap  =  this.prjQuatPrpsService.getDecimalDigitsByBuOrgCode();
		view.addObject("cntWayCdListJSON", JSON.toJSONString(cntWayCdList));
		view.addObject("prjId", prjId);
		view.addObject("quatPrps", quatPrps);//配置方案信息
		view.addObject("quatPrpsJson", quatPrps==null?"": JSON.toJSONString(quatPrps));//配置方案信息
		view.addObject("PrjQuatPrpsCfgDetailList", list);//配置明细信息
		view.addObject("lsPdUntCdList", lsPdUntCdList);//租赁期数单位
		view.addObject("payWayCdList", payWayCdList);//支付方式
		view.addObject("lsCalWayCdList", lsCalWayCdList);//计算方式
		view.addObject("calBaseCdList", calBaseCdList);//费用计算基数
		view.addObject("cntWayCdList", cntWayCdList);///费用计入方式
		view.addObject("intRateWayCdList", intRateWayCdList);//租赁年利率计算方式
		view.addObject("dpstHdlWayCdList", dpstHdlWayCdList);//客户保证金处理方式
		view.addObject("expHdlWayCdList", expHdlWayCdList);//租赁期满处理方式
		view.addObject("prdNum", prdNum);//产品数量 
		view.addObject("totalPrdAmt",totalPrdAmtStr); 
		view.addObject("totalRsrvPcStr",totalRsrvPcStr);//留购价总金额
		view.addObject("detailFlag",detailFlag); 
		view.addObject("prpsCfgId", prpsCfgId);
		view.addObject("scaleNumMap", scaleNumMap.isEmpty()==true?"":JSON.toJSONString(scaleNumMap));
		view.addObject("prpsTypCd", prpsTypCd);
		view.addObject("prjQuatSplitPctList", prjQuatSplitPctList);
		//添加事业部，项目类型
		view.addObject("buOrgCd",null==prjBscInfoVO?"":prjBscInfoVO.getBuOrgCd());
		view.addObject("prjTypCd",null==prjBscInfoVO?"":prjBscInfoVO.getPrjTypCd());
		return view;
	}

	/**
	 * 到工商银行测算页面
	 */
	@RequestMapping(value = "/toAddCarBankPage.do", method = { RequestMethod.GET, RequestMethod.POST })
	public ModelAndView toAddCarBankPage(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String prjId = request.getParameter("prjId");
		String id = request.getParameter("id");
		String detailFlag = request.getParameter("detailFlag");
		ModelAndView view = new ModelAndView("project/prjquatprps/prjQuatPrpsCarBankAdd");
		String prpsCfgId=request.getParameter("prpsCfgId");
		String prpsTypCd = request.getParameter("prpsTypCd");
		PrjQuatPrpsCfgMVO 	quatPrps = null;
		List<PrjQuatPrpsCfgDVO> list = null;
		Integer isNew = null;
		double initLsPct = 0d;
		int prdNum = 0;
		double totalPrdAmt=0d;
		double totalRsrvPc = 0d;
			//购置税
				double insuTotalAmt = 0d;
				Long prjPrdId = null;
				String buOrgCd = "";
				List<PrjPrdBscInfoVO> prdList= null;
		PrjPrdBscInfoQueryCondition prdQc = new PrjPrdBscInfoQueryCondition();
		if(StringUtils.isNotBlank(prjId)){
			prdQc.setPrjId(Long.valueOf(prjId));
			 prdList=	this.prjPrdBscInfoService.searchList(prdQc);
			if(CollectionUtils.isNotEmpty(prdList)){
				prjPrdId = prdList.get(0).getId();
				for (PrjPrdBscInfoVO prjPrdBscInfoVO : prdList) {
					totalPrdAmt += DecimalUtils.mul(prjPrdBscInfoVO.getGuidePc(), prjPrdBscInfoVO.getPrdQty());
					totalRsrvPc +=DecimalUtils.mul(prjPrdBscInfoVO.getRsrvPc(), prjPrdBscInfoVO.getPrdQty());
					if(null!=prjPrdBscInfoVO.getIsNew()){
						isNew = prjPrdBscInfoVO.getIsNew();
					}
				}
			}
		}
		PrjBscInfoVO prjBscInfoVO = 	this.prjBscInfoService.selectById(Long.valueOf(prjId));
		String prjTypCd = prjBscInfoVO.getPrjTypCd();
		if(StringUtils.isNotEmpty(prpsCfgId)){
			quatPrps = 	this.prjQuatPrpsCfgMService.selectById(Long.valueOf(prpsCfgId));
			Pager page = new Pager();

			//专车事业部设置购置税、保险、返利
			buOrgCd = prjBscInfoVO.getBuOrgCd();
			PrjQuatPrpsCfgDQueryCondition qc = new PrjQuatPrpsCfgDQueryCondition();
			page.setEveryPage(Integer.MAX_VALUE);//最大数据量
			qc.setPrpsCfgId(Long.valueOf(prpsCfgId));
			page.setCondition(qc);
			Pager pager = this.prjQuatPrpsCfgDService.searchListPage(page);
			list = (List<PrjQuatPrpsCfgDVO>) pager.getResultList();
			Integer isInsBiz = prjBscInfoVO.getIsInsBiz();
			if(!(PrjBscInfoConstant.CODE_BU_ORG_CD_XNY.equals(buOrgCd) && !(BaseConstant.IS_YESNO_YES == isInsBiz))){
				InsRouteBscInfoVO insRouteBscInfoVO = this.insRouteBscInfoService.searchListByPrjId(Long.valueOf(prjId));
				logger.info("toAddCarBankPage获取路由信息.查询路由数据结果insRouteBscInfoVO:{}", JSON.toJSONString(insRouteBscInfoVO));
				List<InsRoutePrpsFeeVO> insRoutePrpsFeeVOList = new ArrayList<InsRoutePrpsFeeVO>();
				if(insRouteBscInfoVO != null){
					quatPrps.setLsPd(insRouteBscInfoVO.getLsPd());
					view.addObject("isBp", insRouteBscInfoVO.getIsBp());//是否包牌
					view.addObject("annIntRatePct", insRouteBscInfoVO.getAnnIntRatePct());//租赁年利率
					insRoutePrpsFeeVOList = insRouteBscInfoVO.getInsRoutePrpsFeeVOList();
				}
				List<InsRoutePrdInfoVO> insRoutePrdInfoVOList = insRouteBscInfoVO.getInsRoutePrdInfoVOList();
				Double mediationFeeAmtSum = 0d;
				if(CollectionUtils.isNotEmpty(insRoutePrdInfoVOList)){
					for (InsRoutePrdInfoVO insRoutePrdInfoVO : insRoutePrdInfoVOList) {
						mediationFeeAmtSum += DecimalUtils.convertFenToYuan(insRoutePrdInfoVO.getMediationFeeAmt()*insRoutePrdInfoVO.getPrdQty());

					}
				}
				Double actAmt = 0d;
				boolean fee76 = false;
				for (PrjQuatPrpsCfgDVO prjQuatPrpsCfgDVO : list) {
					String feeTypCd = prjQuatPrpsCfgDVO.getFeeTypCd();
					if(PrjQuatPrpsFeeConstant.FEE_TYP_CD_76.equals(feeTypCd)
					){
						fee76 = true;
						prjQuatPrpsCfgDVO.setFixedAmt(mediationFeeAmtSum);
						if(PrjBscInfoConstant.PRJ_TYP_CD_CDDYWUL.equals(prjTypCd) || PrjBscInfoConstant.PRJ_TYP_CD_ESCJYD.equals(prjTypCd) || PrjBscInfoConstant.PRJ_TYP_CD_OWNJYD.equals(prjTypCd)){
							prjQuatPrpsCfgDVO.setCntWayCd(PrjQuatPrpsConstant.CODE_PRJ_QUAT_CNT_WAY_CONT);
							prjQuatPrpsCfgDVO.setCntWayCdNm("计入合同额");
							prjQuatPrpsCfgDVO.setIsAllowChg(BaseConstant.IS_YESNO_NO);
						}else{
							prjQuatPrpsCfgDVO.setCntWayCd(PrjQuatPrpsConstant.CODE_PRJ_QUAT_CNT_WAY_OTH);
							prjQuatPrpsCfgDVO.setCntWayCdNm("其他费用");
						}
						prjQuatPrpsCfgDVO.setIsFixedAmt(BaseConstant.IS_YESNO_YES);
						prjQuatPrpsCfgDVO.setIsFixedAmtNm("是");
					}
					if(StringUtils.isNotEmpty(feeTypCd)
							&& (PrjQuatPrpsFeeConstant.FEE_TYP_CD_01.equals(feeTypCd)
							|| PrjQuatPrpsFeeConstant.FEE_TYP_CD_02.equals(feeTypCd)
							|| PrjQuatPrpsFeeConstant.FEE_TYP_CD_63.equals(feeTypCd)
							|| PrjQuatPrpsFeeConstant.FEE_TYP_CD_64.equals(feeTypCd))){
						if(CollectionUtils.isNotEmpty(insRoutePrpsFeeVOList)){
							for (InsRoutePrpsFeeVO insRoutePrpsFeeVO : insRoutePrpsFeeVOList) {
								if(PrjQuatPrpsFeeConstant.FEE_TYP_CD_01.equals(insRoutePrpsFeeVO.getFeeTypCd())){
									actAmt = insRouteBscInfoVO.getContAmt() - insRoutePrpsFeeVO.getFeeAmt();
								}
							}
							for (InsRoutePrpsFeeVO insRoutePrpsFeeVO : insRoutePrpsFeeVOList) {
								if(feeTypCd.equals(insRoutePrpsFeeVO.getFeeTypCd())){
									if(null!=insRoutePrpsFeeVO.getFeeAmt()){
										prjQuatPrpsCfgDVO.setFixedAmt(DecimalUtils.convertFenToYuan(insRoutePrpsFeeVO.getFeeAmt().longValue()));
									}
									if(null!=insRoutePrpsFeeVO.getFeePct() && insRoutePrpsFeeVO.getFeePct().doubleValue() != 0){
										prjQuatPrpsCfgDVO.setFeePct(insRoutePrpsFeeVO.getFeePct());
									}
									if(null!=insRoutePrpsFeeVO.getCntWayCd()){
										prjQuatPrpsCfgDVO.setCntWayCd(insRoutePrpsFeeVO.getCntWayCd());
									}
									if(null!=insRoutePrpsFeeVO.getIsFixedAmt()){
										prjQuatPrpsCfgDVO.setIsFixedAmt(insRoutePrpsFeeVO.getIsFixedAmt());
									}
									if(PrjQuatPrpsFeeConstant.FEE_TYP_CD_02.equals(feeTypCd)){
										if(StringUtils.isNotBlank(insRoutePrpsFeeVO.getCalBaseCd())
												&& !((insRoutePrpsFeeVO.getCalBaseCd()).equals(prjQuatPrpsCfgDVO.getCalBaseCd()))){
											if(PrjQuatPrpsConstant.CODE_CAL_BASE_CONTRACT.equals(prjQuatPrpsCfgDVO.getCalBaseCd())){
												if(null!=insRoutePrpsFeeVO.getFeeAmt()){
													prjQuatPrpsCfgDVO.setFeePct(DecimalUtils.div(insRoutePrpsFeeVO.getFeeAmt(),insRouteBscInfoVO.getContAmt(),10)*100);
												}
											}else if(PrjQuatPrpsConstant.CODE_CAL_BASE_FINANCING.equals(prjQuatPrpsCfgDVO.getCalBaseCd())){
												prjQuatPrpsCfgDVO.setFeePct(DecimalUtils.div(insRoutePrpsFeeVO.getFeeAmt(),actAmt,10)*100);
											}
                                            view.addObject("insRouteInfo", "由于该报价方案客户保证金计算基数与资管路由不一致，系统已重新推算比例值");
										}
									}
								}
							}
						}
					}
				}
				if(mediationFeeAmtSum != 0 && !fee76){
					PrjQuatPrpsCfgDVO prjQuatPrpsCfgDVO = new PrjQuatPrpsCfgDVO();
					prjQuatPrpsCfgDVO.setPrpsCfgId(list.get(0).getPrpsCfgId());
					prjQuatPrpsCfgDVO.setFeeTypCd(PrjQuatPrpsFeeConstant.FEE_TYP_CD_76);
					prjQuatPrpsCfgDVO.setFeeTypCdNm("调节费");
					prjQuatPrpsCfgDVO.setIsAllowChg(BaseConstant.IS_YESNO_YES);
					prjQuatPrpsCfgDVO.setIsAllowChgNm("是");
					prjQuatPrpsCfgDVO.setIsSysDef(BaseConstant.IS_YESNO_NO);
					prjQuatPrpsCfgDVO.setIsSysDefNm("否");
					prjQuatPrpsCfgDVO.setFixedAmt(mediationFeeAmtSum);
					if(PrjBscInfoConstant.PRJ_TYP_CD_CDDYWUL.equals(prjTypCd) || PrjBscInfoConstant.PRJ_TYP_CD_ESCJYD.equals(prjTypCd) || PrjBscInfoConstant.PRJ_TYP_CD_OWNJYD.equals(prjTypCd)){
						prjQuatPrpsCfgDVO.setCntWayCd(PrjQuatPrpsConstant.CODE_PRJ_QUAT_CNT_WAY_CONT);
						prjQuatPrpsCfgDVO.setCntWayCdNm("计入合同额");
						prjQuatPrpsCfgDVO.setIsAllowChg(BaseConstant.IS_YESNO_NO);
					}else{
						prjQuatPrpsCfgDVO.setCntWayCd(PrjQuatPrpsConstant.CODE_PRJ_QUAT_CNT_WAY_OTH);
						prjQuatPrpsCfgDVO.setCntWayCdNm("其他费用");
					}
					prjQuatPrpsCfgDVO.setIsFixedAmt(BaseConstant.IS_YESNO_YES);
					prjQuatPrpsCfgDVO.setIsFixedAmtNm("是");
					list.add(prjQuatPrpsCfgDVO);
				}
			}
		}
		
		BigDecimal bd = new BigDecimal(totalPrdAmt); 
		String totalPrdAmtStr = bd.toPlainString();
		
		BigDecimal rsrvPc = new BigDecimal(DecimalUtils.convertFenToYuan(new Double(totalRsrvPc).longValue())); 
		String totalRsrvPcStr = rsrvPc.toPlainString();
		//根据id查询修改数据
		if(StringUtils.isNotBlank(id)){
			//查询已经保存的报价方案
			PrjQuatPrpsVO prjQuatPrps = this.prjQuatPrpsService.selectById(Long.valueOf(id));
			ListPageVO<PrjQuatPrpsPaySchVO> payListPage = new ListPageVO<PrjQuatPrpsPaySchVO>(prjQuatPrps.getPrjQuatPrpsPaySchList(),prjQuatPrps.getPrjQuatPrpsPaySchList().size());
			prjQuatPrps.setPrjQuatPrpsPaySchPage(payListPage);
			ListPageVO<PrjQuatPrpsFeeVO> detailListPage = new ListPageVO<PrjQuatPrpsFeeVO>(prjQuatPrps.getPrjQuatPrpsFeelist(),prjQuatPrps.getPrjQuatPrpsFeelist().size());
			prjQuatPrps.setPrjQuatPrpsFeePage(detailListPage);
			view.addObject("detailListPage", JSON.toJSONString(detailListPage));
			view.addObject("payListPage", JSON.toJSONString(payListPage));
			view.addObject("prjQuatPrps", JSON.toJSONString(prjQuatPrps));
            view.addObject("cstIrr", prjQuatPrps.getCstIrr());
			prpsTypCd = prjQuatPrps.getPrpsTypCd();
		}
		view.addObject("id", id);
		//租赁期数单位
		List<KeyValueVO> lsPdUntCdList = this.prjQuatPrpsCfgMService.searchLsPdUntCdList();
		view.addObject("lsPdUntCdList", lsPdUntCdList);
		//支付方式
		List<KeyValueVO> payWayCdList = this.prjBscInfoService.getKeyValueList(DictionaryConstant.CODE_PRJ_QUAT_PAY_WAY_CD,CurrentThreadContext.getCurrentSysCd(),prjBscInfoVO.getCstMgrOrgCd());
		/*List<KeyValueVO> payWayCdList = this.prjQuatPrpsCfgMService.searchPayWayCdList();*/
		view.addObject("payWayCdList", payWayCdList);
		//保证金处理方式
		List<KeyValueVO> dpstHdlWayCdList = this.prjQuatPrpsCfgMService.searchDpstHdlWayCdList();
		view.addObject("dpstHdlWayCdList", dpstHdlWayCdList);
		//租赁期满处理方式
		List<KeyValueVO> expHdlWayCdList = this.prjQuatPrpsCfgMService.searchExpHdlWayCdList();
		view.addObject("expHdlWayCdList", expHdlWayCdList);
		//不还款处理方式
		List<KeyValueVO> noPayWayCdList = this.prjBscInfoService.searchNoPayWayCdList();
		view.addObject("noPayWayCdList", noPayWayCdList);
		//费用类型
		JSONArray feeTypCdListJSON = this.prjQuatPrpsCfgMService.searchFeeTypCdList();
		view.addObject("feeTypCdListJSON", feeTypCdListJSON);
		//费用计算基数
		List<KeyValueVO> calBaseCdList = this.prjQuatPrpsCfgMService.searchCalBaseCdList();
		view.addObject("calBaseCdListJSON", JSON.toJSONString(calBaseCdList));
		List<KeyValueVO> yesNoCdList = this.prjQuatPrpsCfgMService.searchYesOrNoCdList();
		view.addObject("yesOrNoCdListJSON",JSON.toJSONString(yesNoCdList) );
		//费用计入方式
		List<KeyValueVO> cntWayCdList = this.prjQuatPrpsCfgMService.searchCntWayCdList();
		//计算方式
		List<KeyValueVO> lsCalWayCdList = this.prjBscInfoService.searchLsCalWayCdList();
		//租赁年利率计算方式
		List<KeyValueVO> intRateWayCdList = this.prjBscInfoService.searchIntRateWayCdList();
		//拆分比例
		List<KeyValueVO> prjQuatSplitPctList = this.prjBscInfoService.getKeyValueList(DictionaryConstant.CODE_QUAT_SPLIT_CD,CurrentThreadContext.getCurrentSysCd(),prjBscInfoVO.getCstMgrOrgCd());
		/*List<KeyValueVO> prjQuatSplitPctList = this.prjBscInfoService.getPrjQuatSplitPctList();*/
		
		//供应商比例
		List<KeyValueVO> splBackPctList = this.prjBscInfoService.getSplBackPctList();
		Map<String,String>  scaleNumMap  =  this.prjQuatPrpsService.getDecimalDigitsByBuOrgCodeNew(prjBscInfoVO.getCstMgrOrgCd());
		view.addObject("cntWayCdListJSON", JSON.toJSONString(cntWayCdList));
		view.addObject("splBackPctListJSON", JSON.toJSONString(splBackPctList));
		view.addObject("prjId", prjId);
		view.addObject("quatPrps", quatPrps);//配置方案信息
		view.addObject("quatPrpsJson", quatPrps==null?"": JSON.toJSONString(quatPrps));//配置方案信息
		view.addObject("PrjQuatPrpsCfgDetailList", list);//配置明细信息
		view.addObject("lsPdUntCdList", lsPdUntCdList);//租赁期数单位
		view.addObject("payWayCdList", payWayCdList);//支付方式
		view.addObject("lsCalWayCdList", lsCalWayCdList);//计算方式
		view.addObject("calBaseCdList", calBaseCdList);//费用计算基数
		view.addObject("cntWayCdList", cntWayCdList);///费用计入方式
		view.addObject("intRateWayCdList", intRateWayCdList);//租赁年利率计算方式
		view.addObject("dpstHdlWayCdList", dpstHdlWayCdList);//客户保证金处理方式
		view.addObject("expHdlWayCdList", expHdlWayCdList);//租赁期满处理方式
		view.addObject("prdNum", prdNum);//产品数量 
		view.addObject("totalPrdAmt",totalPrdAmtStr); 
		view.addObject("totalRsrvPcStr",totalRsrvPcStr);//留购价总金额
		view.addObject("detailFlag",detailFlag); 
		view.addObject("prpsCfgId", prpsCfgId);
		view.addObject("scaleNumMap", scaleNumMap.isEmpty()==true?"":JSON.toJSONString(scaleNumMap));
		view.addObject("prpsTypCd", prpsTypCd);
		view.addObject("prjQuatSplitPctList", prjQuatSplitPctList);
		view.addObject("insuTotalAmt", insuTotalAmt);
		view.addObject("buOrgCd", buOrgCd);
		view.addObject("initLsPct", initLsPct);
		view.addObject("isNew", isNew);
		return view;
	}

	

	/**
	 * 到重卡工商银行测算页面
	 */
	@RequestMapping(value = "/toAddZKBankPage.do", method = { RequestMethod.GET, RequestMethod.POST })
	public ModelAndView toAddZKBankPage(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String prjId = request.getParameter("prjId");
		String id = request.getParameter("id");
		String detailFlag = request.getParameter("detailFlag");
		ModelAndView view = new ModelAndView("project/prjquatprps/prjQuatPrpsZKBankAdd");
		String prpsCfgId=request.getParameter("prpsCfgId");
		String prpsTypCd = request.getParameter("prpsTypCd");
		PrjQuatPrpsCfgMVO 	quatPrps = null;
		List<PrjQuatPrpsCfgDVO> list = null;
		Integer isNew = null;
		double initLsPct = 0d;
		int prdNum = 0;
		double totalPrdAmt=0d;
		double totalRsrvPc = 0d;
		double floatPct = 0d;//上浮比例
			//购置税
				double insuTotalAmt = 0d;
				Long prjPrdId = null;
				String buOrgCd = "";
				List<PrjPrdBscInfoVO> prdList= null;
		PrjPrdBscInfoQueryCondition prdQc = new PrjPrdBscInfoQueryCondition();
		if(StringUtils.isNotBlank(prjId)){
			prdQc.setPrjId(Long.valueOf(prjId));
			 prdList=	this.prjPrdBscInfoService.searchList(prdQc);
			if(CollectionUtils.isNotEmpty(prdList)){
				prjPrdId = prdList.get(0).getId();
				for (PrjPrdBscInfoVO prjPrdBscInfoVO : prdList) {
					totalPrdAmt += DecimalUtils.mul(prjPrdBscInfoVO.getGuidePc(), prjPrdBscInfoVO.getPrdQty());
					totalRsrvPc +=DecimalUtils.mul(prjPrdBscInfoVO.getRsrvPc(), prjPrdBscInfoVO.getPrdQty());
					if(null!=prjPrdBscInfoVO.getIsNew()){
						isNew = prjPrdBscInfoVO.getIsNew();
					}
				}
			}
		}
		PrjBscInfoVO prjBscInfoVO = 	this.prjBscInfoService.selectById(Long.valueOf(prjId));
		String prjTypCd = prjBscInfoVO.getPrjTypCd();
		buOrgCd = prjBscInfoVO.getBuOrgCd();
		if(StringUtils.isNotEmpty(prpsCfgId)){
			quatPrps = 	this.prjQuatPrpsCfgMService.selectById(Long.valueOf(prpsCfgId));
			Pager page = new Pager();
			//专车事业部设置购置税、保险、返利
			PrjQuatPrpsCfgDQueryCondition qc = new PrjQuatPrpsCfgDQueryCondition();
			page.setEveryPage(Integer.MAX_VALUE);//最大数据量
			qc.setPrpsCfgId(Long.valueOf(prpsCfgId));
			page.setCondition(qc);
			Pager pager = this.prjQuatPrpsCfgDService.searchListPage(page);
			list = (List<PrjQuatPrpsCfgDVO>) pager.getResultList();
			logger.info("toAddZKBankPage方案费用项初始化.路由前结果list:{}",JSON.toJSONString(list));
			Integer isInsBiz = prjBscInfoVO.getIsInsBiz();
			if(!(PrjBscInfoConstant.CODE_BU_ORG_CD_XNY.equals(buOrgCd) && !(BaseConstant.IS_YESNO_YES == isInsBiz))){
				InsRouteBscInfoVO insRouteBscInfoVO = this.insRouteBscInfoService.searchListByPrjId(Long.valueOf(prjId));
				logger.info("toAddZKBankPage获取路由信息.查询路由数据结果insRouteBscInfoVO:{}",JSON.toJSONString(insRouteBscInfoVO));
				List<InsRoutePrpsFeeVO> insRoutePrpsFeeVOList = new ArrayList<InsRoutePrpsFeeVO>();
				if(insRouteBscInfoVO != null){
					quatPrps.setLsPd(insRouteBscInfoVO.getLsPd());
					view.addObject("isBp", insRouteBscInfoVO.getIsBp());//是否包牌
					view.addObject("annIntRatePct", insRouteBscInfoVO.getAnnIntRatePct());//租赁年利率
					insRoutePrpsFeeVOList = insRouteBscInfoVO.getInsRoutePrpsFeeVOList();
				}
				List<InsRoutePrdInfoVO> insRoutePrdInfoVOList = insRouteBscInfoVO.getInsRoutePrdInfoVOList();
				Double mediationFeeAmtSum = 0d;
				if(CollectionUtils.isNotEmpty(insRoutePrdInfoVOList)){
					for (InsRoutePrdInfoVO insRoutePrdInfoVO : insRoutePrdInfoVOList) {
						mediationFeeAmtSum += DecimalUtils.convertFenToYuan(insRoutePrdInfoVO.getMediationFeeAmt()*insRoutePrdInfoVO.getPrdQty());

					}
				}
				Double actAmt = 0d;
				boolean fee76 = false;
				for (PrjQuatPrpsCfgDVO prjQuatPrpsCfgDVO : list) {
					String feeTypCd = prjQuatPrpsCfgDVO.getFeeTypCd();
					if(PrjQuatPrpsFeeConstant.FEE_TYP_CD_76.equals(feeTypCd)){
						fee76 = true;
						prjQuatPrpsCfgDVO.setFixedAmt(mediationFeeAmtSum);
						if(PrjBscInfoConstant.PRJ_TYP_CD_CDDYWUL.equals(prjTypCd) || PrjBscInfoConstant.PRJ_TYP_CD_ESCJYD.equals(prjTypCd) || PrjBscInfoConstant.PRJ_TYP_CD_OWNJYD.equals(prjTypCd)){
							prjQuatPrpsCfgDVO.setCntWayCd(PrjQuatPrpsConstant.CODE_PRJ_QUAT_CNT_WAY_CONT);
							prjQuatPrpsCfgDVO.setCntWayCdNm("计入合同额");
							prjQuatPrpsCfgDVO.setIsAllowChg(BaseConstant.IS_YESNO_NO);
						}else{
							prjQuatPrpsCfgDVO.setCntWayCd(PrjQuatPrpsConstant.CODE_PRJ_QUAT_CNT_WAY_OTH);
							prjQuatPrpsCfgDVO.setCntWayCdNm("其他费用");
						}
						prjQuatPrpsCfgDVO.setIsFixedAmt(BaseConstant.IS_YESNO_YES);
						prjQuatPrpsCfgDVO.setIsFixedAmtNm("是");
					}
					if(StringUtils.isNotEmpty(feeTypCd)
							&& (PrjQuatPrpsFeeConstant.FEE_TYP_CD_01.equals(feeTypCd)
							|| PrjQuatPrpsFeeConstant.FEE_TYP_CD_02.equals(feeTypCd)
							|| PrjQuatPrpsFeeConstant.FEE_TYP_CD_63.equals(feeTypCd)
							|| PrjQuatPrpsFeeConstant.FEE_TYP_CD_64.equals(feeTypCd))){
						if(CollectionUtils.isNotEmpty(insRoutePrpsFeeVOList)){
							for (InsRoutePrpsFeeVO insRoutePrpsFeeVO : insRoutePrpsFeeVOList) {
								if(PrjQuatPrpsFeeConstant.FEE_TYP_CD_01.equals(insRoutePrpsFeeVO.getFeeTypCd())){
									actAmt = insRouteBscInfoVO.getContAmt() - insRoutePrpsFeeVO.getFeeAmt();
								}
							}
							for (InsRoutePrpsFeeVO insRoutePrpsFeeVO : insRoutePrpsFeeVOList) {
								if(feeTypCd.equals(insRoutePrpsFeeVO.getFeeTypCd())){
									if(null!=insRoutePrpsFeeVO.getFeeAmt()){
										prjQuatPrpsCfgDVO.setFixedAmt(DecimalUtils.convertFenToYuan(insRoutePrpsFeeVO.getFeeAmt().longValue()));
									}
									if(null!=insRoutePrpsFeeVO.getFeePct() && insRoutePrpsFeeVO.getFeePct().doubleValue() != 0){
										prjQuatPrpsCfgDVO.setFeePct(insRoutePrpsFeeVO.getFeePct());
									}
									if(null!=insRoutePrpsFeeVO.getCntWayCd()){
										prjQuatPrpsCfgDVO.setCntWayCd(insRoutePrpsFeeVO.getCntWayCd());
									}
									if(null!=insRoutePrpsFeeVO.getIsFixedAmt()){
										prjQuatPrpsCfgDVO.setIsFixedAmt(insRoutePrpsFeeVO.getIsFixedAmt());
									}
									if(PrjQuatPrpsFeeConstant.FEE_TYP_CD_02.equals(feeTypCd)){
										if(StringUtils.isNotBlank(insRoutePrpsFeeVO.getCalBaseCd())
												&& !((insRoutePrpsFeeVO.getCalBaseCd()).equals(prjQuatPrpsCfgDVO.getCalBaseCd()))){
											if(PrjQuatPrpsConstant.CODE_CAL_BASE_CONTRACT.equals(prjQuatPrpsCfgDVO.getCalBaseCd())){
												if(null!=insRoutePrpsFeeVO.getFeeAmt()){
													prjQuatPrpsCfgDVO.setFeePct(DecimalUtils.div(insRoutePrpsFeeVO.getFeeAmt(),insRouteBscInfoVO.getContAmt(),10)*100);
												}
											}else if(PrjQuatPrpsConstant.CODE_CAL_BASE_FINANCING.equals(prjQuatPrpsCfgDVO.getCalBaseCd())){
												prjQuatPrpsCfgDVO.setFeePct(DecimalUtils.div(insRoutePrpsFeeVO.getFeeAmt(),actAmt,10)*100);
											}
                                            view.addObject("insRouteInfo", "由于该报价方案客户保证金计算基数与资管路由不一致，系统已重新推算比例值");
										}
									}
								}
							}
						}
					}
				}
				if(mediationFeeAmtSum != 0 && !fee76){
					PrjQuatPrpsCfgDVO prjQuatPrpsCfgDVO = new PrjQuatPrpsCfgDVO();
					prjQuatPrpsCfgDVO.setPrpsCfgId(list.get(0).getPrpsCfgId());
					prjQuatPrpsCfgDVO.setFeeTypCd(PrjQuatPrpsFeeConstant.FEE_TYP_CD_76);
					prjQuatPrpsCfgDVO.setFeeTypCdNm("调节费");
					prjQuatPrpsCfgDVO.setIsAllowChg(BaseConstant.IS_YESNO_YES);
					prjQuatPrpsCfgDVO.setIsAllowChgNm("是");
					prjQuatPrpsCfgDVO.setIsSysDef(BaseConstant.IS_YESNO_NO);
					prjQuatPrpsCfgDVO.setIsSysDefNm("否");
					prjQuatPrpsCfgDVO.setFixedAmt(mediationFeeAmtSum);
					if(PrjBscInfoConstant.PRJ_TYP_CD_CDDYWUL.equals(prjTypCd) || PrjBscInfoConstant.PRJ_TYP_CD_ESCJYD.equals(prjTypCd) || PrjBscInfoConstant.PRJ_TYP_CD_OWNJYD.equals(prjTypCd)){
						prjQuatPrpsCfgDVO.setCntWayCd(PrjQuatPrpsConstant.CODE_PRJ_QUAT_CNT_WAY_CONT);
						prjQuatPrpsCfgDVO.setCntWayCdNm("计入合同额");
						prjQuatPrpsCfgDVO.setIsAllowChg(BaseConstant.IS_YESNO_NO);
					}else{
						prjQuatPrpsCfgDVO.setCntWayCd(PrjQuatPrpsConstant.CODE_PRJ_QUAT_CNT_WAY_OTH);
						prjQuatPrpsCfgDVO.setCntWayCdNm("其他费用");
					}
					prjQuatPrpsCfgDVO.setIsFixedAmt(BaseConstant.IS_YESNO_YES);
					prjQuatPrpsCfgDVO.setIsFixedAmtNm("是");
					list.add(prjQuatPrpsCfgDVO);
				}
			}
		}
		
		BigDecimal bd = new BigDecimal(totalPrdAmt); 
		String totalPrdAmtStr = bd.toPlainString();
		
		BigDecimal rsrvPc = new BigDecimal(DecimalUtils.convertFenToYuan(new Double(totalRsrvPc).longValue())); 
		String totalRsrvPcStr = rsrvPc.toPlainString();
		//根据id查询修改数据
		if(StringUtils.isNotBlank(id)){
			//查询已经保存的报价方案
			PrjQuatPrpsVO prjQuatPrps = this.prjQuatPrpsService.selectById(Long.valueOf(id));
			ListPageVO<PrjQuatPrpsPaySchVO> payListPage = new ListPageVO<PrjQuatPrpsPaySchVO>(prjQuatPrps.getPrjQuatPrpsPaySchList(),prjQuatPrps.getPrjQuatPrpsPaySchList().size());
			prjQuatPrps.setPrjQuatPrpsPaySchPage(payListPage);
			ListPageVO<PrjQuatPrpsFeeVO> detailListPage = new ListPageVO<PrjQuatPrpsFeeVO>(prjQuatPrps.getPrjQuatPrpsFeelist(),prjQuatPrps.getPrjQuatPrpsFeelist().size());
			prjQuatPrps.setPrjQuatPrpsFeePage(detailListPage);
			//查询支付表上上装的期数信息
			PrjPrdDtlQueryCondition dtlQc = new PrjPrdDtlQueryCondition();
			dtlQc.setPrjId(Long.valueOf(prjId));
			List<PrjPrdDtlVO> dtlList = this.prjPrdDtlService.selectList(dtlQc);
			Long payId = null;
			Long ghPayId = null;
			if(CollectionUtils.isNotEmpty(dtlList)){
				for (PrjPrdDtlVO prjPrdDtlVO : dtlList) {
					if(StringUtils.isNotBlank(prjPrdDtlVO.getPrdMdl())&&prjPrdDtlVO.getPrdMdl().equals(PrjPrdBscInfoConstant.PRJ_PRD_TYP_GH)){
						payId = prjPrdDtlVO.getPaySchId();
					}else{
						ghPayId = prjPrdDtlVO.getPaySchId();
					}
				}
				if(null!=payId){
					PrjPrdPaySchMVO prjPrdPaySchMVO = this.prjPrdPaySchMService.selectById(payId);
					if(null!=prjPrdPaySchMVO){
						prjQuatPrps.setLsPd2(prjPrdPaySchMVO.getLsPd().longValue());
						prjQuatPrps.setSzRntAmt(DecimalUtils.convertFenToYuan(prjPrdPaySchMVO.getEachEstRntAmt().longValue()));
					}
				}
				if(null!=ghPayId){
					PrjPrdPaySchMVO prjPrdPaySchMVO = this.prjPrdPaySchMService.selectById(ghPayId);
					if(null!=prjPrdPaySchMVO){
						prjQuatPrps.setGhRntAmt(DecimalUtils.convertFenToYuan(prjPrdPaySchMVO.getEachEstRntAmt().longValue()));
						prjQuatPrps.setGhActLsAmt(DecimalUtils.convertFenToYuan(prjPrdPaySchMVO.getActLsAmt().longValue()));//工行融资额

					}
				}
			}
			view.addObject("detailListPage", JSON.toJSONString(detailListPage));
			view.addObject("payListPage", JSON.toJSONString(payListPage));
			view.addObject("prjQuatPrps", JSON.toJSONString(prjQuatPrps));
            view.addObject("cstIrr", prjQuatPrps.getCstIrr());
			prpsTypCd = prjQuatPrps.getPrpsTypCd();
		}
		view.addObject("id", id);
		//租赁期数单位
		List<KeyValueVO> lsPdUntCdList = this.prjQuatPrpsCfgMService.searchLsPdUntCdList();
		view.addObject("lsPdUntCdList", lsPdUntCdList);
		//支付方式
		List<KeyValueVO> payWayCdList = this.prjBscInfoService.getKeyValueList(DictionaryConstant.CODE_PRJ_QUAT_PAY_WAY_CD,CurrentThreadContext.getCurrentSysCd(),prjBscInfoVO.getCstMgrOrgCd());
		/*List<KeyValueVO> payWayCdList = this.prjQuatPrpsCfgMService.searchPayWayCdList();*/
		view.addObject("payWayCdList", payWayCdList);
		//保证金处理方式
		List<KeyValueVO> dpstHdlWayCdList = this.prjQuatPrpsCfgMService.searchDpstHdlWayCdList();
		view.addObject("dpstHdlWayCdList", dpstHdlWayCdList);
		//租赁期满处理方式
		List<KeyValueVO> expHdlWayCdList = this.prjQuatPrpsCfgMService.searchExpHdlWayCdList();
		view.addObject("expHdlWayCdList", expHdlWayCdList);
		//不还款处理方式
		List<KeyValueVO> noPayWayCdList = this.prjBscInfoService.searchNoPayWayCdList();
		view.addObject("noPayWayCdList", noPayWayCdList);
		//费用类型
		JSONArray feeTypCdListJSON = this.prjQuatPrpsCfgMService.searchFeeTypCdList();
		view.addObject("feeTypCdListJSON", feeTypCdListJSON);
		//费用计算基数
		List<KeyValueVO> calBaseCdList = this.prjQuatPrpsCfgMService.searchCalBaseCdList();
		view.addObject("calBaseCdListJSON", JSON.toJSONString(calBaseCdList));
		List<KeyValueVO> yesNoCdList = this.prjQuatPrpsCfgMService.searchYesOrNoCdList();
		view.addObject("yesOrNoCdListJSON",JSON.toJSONString(yesNoCdList) );
		//费用计入方式
		List<KeyValueVO> cntWayCdList = this.prjQuatPrpsCfgMService.searchCntWayCdList();
		//计算方式
		List<KeyValueVO> lsCalWayCdList = this.prjBscInfoService.searchLsCalWayCdList();
		//租赁年利率计算方式
		List<KeyValueVO> intRateWayCdList = this.prjBscInfoService.searchIntRateWayCdList();
		//拆分比例
		List<KeyValueVO> prjQuatSplitPctList = this.prjBscInfoService.getKeyValueList(DictionaryConstant.CODE_QUAT_SPLIT_CD,CurrentThreadContext.getCurrentSysCd(),prjBscInfoVO.getCstMgrOrgCd());
		/*List<KeyValueVO> prjQuatSplitPctList = this.prjBscInfoService.getPrjQuatSplitPctList();*/
		
		//供应商比例
		List<KeyValueVO> splBackPctList = this.prjBscInfoService.getSplBackPctList();
		//工行上浮比例
		List<SysDictionaryDTO>  floatPctList = this.sysDictionaryApiService.searchGroup(CurrentThreadContext.getCurrentSysCd(), buOrgCd, DictionaryConstant.CODE__PRJ_PRD_PAY_GH_FLOAT_PCT);
		if(CollectionUtils.isNotEmpty(floatPctList)){
			for (SysDictionaryDTO sysDictionaryDTO : floatPctList) {
				if(StringUtils.isNotBlank(sysDictionaryDTO.getCodeAttr1())&&sysDictionaryDTO.getCodeAttr1().equals(String.valueOf(BaseConstant.IS_YESNO_YES))){
					floatPct = Double.valueOf(sysDictionaryDTO.getCode());
				}
			}
		}
		Map<String,String>  scaleNumMap  =  this.prjQuatPrpsService.getDecimalDigitsByBuOrgCodeNew(prjBscInfoVO.getCstMgrOrgCd());
		view.addObject("cntWayCdListJSON", JSON.toJSONString(cntWayCdList));
		view.addObject("splBackPctListJSON", JSON.toJSONString(splBackPctList));
		view.addObject("prjId", prjId);
		view.addObject("quatPrps", quatPrps);//配置方案信息
		view.addObject("quatPrpsJson", quatPrps==null?"": JSON.toJSONString(quatPrps));//配置方案信息
		view.addObject("PrjQuatPrpsCfgDetailList", list);//配置明细信息
		view.addObject("lsPdUntCdList", lsPdUntCdList);//租赁期数单位
		view.addObject("payWayCdList", payWayCdList);//支付方式
		view.addObject("lsCalWayCdList", lsCalWayCdList);//计算方式
		view.addObject("calBaseCdList", calBaseCdList);//费用计算基数
		view.addObject("cntWayCdList", cntWayCdList);///费用计入方式
		view.addObject("intRateWayCdList", intRateWayCdList);//租赁年利率计算方式
		view.addObject("dpstHdlWayCdList", dpstHdlWayCdList);//客户保证金处理方式
		view.addObject("expHdlWayCdList", expHdlWayCdList);//租赁期满处理方式
		view.addObject("prdNum", prdNum);//产品数量 
		view.addObject("totalPrdAmt",totalPrdAmtStr); 
		view.addObject("totalRsrvPcStr",totalRsrvPcStr);//留购价总金额
		view.addObject("detailFlag",detailFlag); 
		view.addObject("prpsCfgId", prpsCfgId);
		view.addObject("scaleNumMap", scaleNumMap.isEmpty()==true?"":JSON.toJSONString(scaleNumMap));
		view.addObject("prpsTypCd", prpsTypCd);
		view.addObject("prjQuatSplitPctList", prjQuatSplitPctList);
		view.addObject("insuTotalAmt", insuTotalAmt);
		view.addObject("buOrgCd", buOrgCd);
		view.addObject("initLsPct", initLsPct);
		view.addObject("floatPct", floatPct);
		view.addObject("isNew", isNew);
		return view;
	}

	/**
	 * 获取项目方案列表
	 * 
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/getPrjQuatCarDetailById.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object getPrjQuatCarDetailById(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String id = request.getParameter("id");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_OPERATE_SUCC);
		if(StringUtils.isEmpty(id)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
			logger.info("获取报价方案详情失败");
			return result;
		}
		List<PrjQuatPrpsFeeVO> feeList = new ArrayList<PrjQuatPrpsFeeVO>();
				//根据id查询修改数据
				//查询已经保存的报价方案
				PrjQuatPrpsVO prjQuatPrps = this.prjQuatPrpsService.selectById(Long.valueOf(id));
				if(CollectionUtils.isNotEmpty(prjQuatPrps.getPrjQuatPrpsFeelist())){
					for (int i=0; i<prjQuatPrps.getPrjQuatPrpsFeelist().size(); i++) {
						PrjQuatPrpsFeeVO feeVO = prjQuatPrps.getPrjQuatPrpsFeelist().get(i);
						if(!feeVO.getCntWayCd().equals(PrjQuatPrpsConstant.CODE_PRJ_QUAT_CNT_WAY_CONT)&&!feeVO.getFeeTypCd().equals(PrjQuatPrpsConstant.CODE_FEE_WAY_TYPE_GPS_BACK)&&!feeVO.getFeeTypCd().equals(PrjQuatPrpsConstant.CODE_FEE_WAY_TYPE_SPL_BACK)){
							feeList.add(feeVO);
						}
					}
				}
		ListPageVO<PrjQuatPrpsFeeVO> detailListPage = new ListPageVO<PrjQuatPrpsFeeVO>(feeList,feeList.size());
		prjQuatPrps.setPrjQuatPrpsFeePage(detailListPage);
		logger.info("获取报价方案详情detailListPage:{}", JSON.toJSONString(detailListPage));
		return detailListPage;
	}
	
	/**
	 * 获取项目方案列表
	 * 
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/getPrjQuatContFeeDetailById.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object getPrjQuatContFeeDetailById(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String prjId = request.getParameter("prjId");
		String id = request.getParameter("id");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_OPERATE_SUCC);
		if(StringUtils.isEmpty(id)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
			logger.info("获取费用项详情失败，id为空");
			return result;
		}
		//查询已经保存的报价方案
		List<PrjQuatPrpsFeeVO> contFeeVOList =  new ArrayList<PrjQuatPrpsFeeVO>();
		//根据id查询修改数据
		//查询已经保存的报价方案
		PrjQuatPrpsVO prjQuatPrps = this.prjQuatPrpsService.selectById(Long.valueOf(id));
		if(CollectionUtils.isNotEmpty(prjQuatPrps.getPrjQuatPrpsFeelist())){
			for (int i=0; i<prjQuatPrps.getPrjQuatPrpsFeelist().size(); i++) {
				PrjQuatPrpsFeeVO feeVO = prjQuatPrps.getPrjQuatPrpsFeelist().get(i);
				if(feeVO.getCntWayCd().equals(PrjQuatPrpsConstant.CODE_PRJ_QUAT_CNT_WAY_CONT)){
					contFeeVOList.add(feeVO);
				}
			}
		}
		ListPageVO<PrjQuatPrpsFeeVO> detailListPage = new ListPageVO<PrjQuatPrpsFeeVO>(contFeeVOList,contFeeVOList.size());
		prjQuatPrps.setPrjQuatPrpsFeePage(detailListPage);
		logger.info("获取费用项详情返回数据:"+JSONObject.toJSONString(detailListPage));
		return detailListPage;
	}
	
	/**
	 * 获取项目方案列表
	 * 
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/getPrjQuatCarDetailByIdForDetailPage.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object getPrjQuatCarDetailByIdForDetailPage(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String prjId = request.getParameter("prjId");
		String id = request.getParameter("id");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_OPERATE_SUCC);
		if(StringUtils.isEmpty(id)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
			logger.info("获取费用项列表失败，id为空");
			return result;
		}
		List<PrjQuatPrpsFeeVO> feeList = new ArrayList<PrjQuatPrpsFeeVO>();
				//根据id查询修改数据
				//查询已经保存的报价方案
				PrjQuatPrpsVO prjQuatPrps = this.prjQuatPrpsService.selectById(Long.valueOf(id));
				if(CollectionUtils.isNotEmpty(prjQuatPrps.getPrjQuatPrpsFeelist())){
					for (int i=0; i<prjQuatPrps.getPrjQuatPrpsFeelist().size(); i++) {
						PrjQuatPrpsFeeVO feeVO = prjQuatPrps.getPrjQuatPrpsFeelist().get(i);
						if(!feeVO.getCntWayCd().equals(PrjQuatPrpsConstant.CODE_PRJ_QUAT_CNT_WAY_CONT)){
							feeList.add(feeVO);
						}
					}
				}
		ListPageVO<PrjQuatPrpsFeeVO> detailListPage = new ListPageVO<PrjQuatPrpsFeeVO>(feeList,feeList.size());
		prjQuatPrps.setPrjQuatPrpsFeePage(detailListPage);
		logger.info("获取费用项列表,返回数据:"+JSONObject.toJSONString(detailListPage));
		return detailListPage;
	}
	
	/**
	 * 从新计算IRR的值
	 */
	@RequestMapping(value = "/addPrpsQuatIRRPct.do", method = { RequestMethod.POST })
	@ResponseBody
	public Object addPrpsQuatIRRPct(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_ADD_SUCC);
		try {
		   this.prjQuatPrpsService.addPrpsQuatIRRPct();
			result.setData("");
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			logger.error("从新计算IRR的值发生异常，msg:{}",ex.getMessage());
		}catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			logger.error("从新计算IRR的值发生异常msg:{}",ex.getMessage());
		}

		return result;
	}
	/**
	 * 到添加页面
	 */
	@RequestMapping(value = "/toAddNewEngeryPage.do", method = { RequestMethod.GET, RequestMethod.POST })
	public ModelAndView toAddNewEngeryPage(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String prjId = request.getParameter("prjId");
		String id = request.getParameter("id");
		String detailFlag = request.getParameter("detailFlag");
		ModelAndView view = new ModelAndView("project/prjquatprps/prjQuatPrpsNewEngeryAdd");
		String prpsCfgId=request.getParameter("prpsCfgId");
		String prpsTypCd = request.getParameter("prpsTypCd");
		PrjQuatPrpsCfgMVO 	quatPrps = null;
		List<PrjQuatPrpsCfgDVO> list = null;
		String isXnyZZYWFlag ="";
		double initLsPct = 0d;
		int prdNum = 0;
		double totalPrdAmt=0d;
		double totalRsrvPc = 0d;
		double  loadAmt = 0d;//借款金额
		//购置税
		double purchTax = 0d;
		double insuTotalAmt = 0d;
		Long prjPrdId = null;
		String buOrgCd = "";
		String prjCstMgrOrgCd = "";
		List<PrjPrdBscInfoVO> prdList= null;
		double quatRsrvPc = 0d;//方案配置留购价
		Integer isAllowChg = 1; //留购价是否可编辑

		//专车事业部设置购置税、保险、返利
		PrjBscInfoVO prjBscInfoVO = 	this.prjBscInfoService.selectById(Long.valueOf(prjId));
		String prjTypCd = prjBscInfoVO.getPrjTypCd();
		buOrgCd = prjBscInfoVO.getBuOrgCd();
		if(StringUtils.isNotEmpty(prpsCfgId)){
			quatPrps = 	this.prjQuatPrpsCfgMService.selectById(Long.valueOf(prpsCfgId));
			Pager page = new Pager();
			PrjQuatPrpsCfgDQueryCondition qc = new PrjQuatPrpsCfgDQueryCondition();
			page.setEveryPage(Integer.MAX_VALUE);//最大数据量
			    qc.setPrpsCfgId(Long.valueOf(prpsCfgId));
				page.setCondition(qc);
				Pager pager = this.prjQuatPrpsCfgDService.searchListPage(page);
				list = (List<PrjQuatPrpsCfgDVO>) pager.getResultList();
			logger.info("toAddNewEngeryPage方案费用项初始化.路由前结果list：{}" , JSON.toJSONString(list));
			Integer isInsBiz = prjBscInfoVO.getIsInsBiz();
			if(!(PrjBscInfoConstant.CODE_BU_ORG_CD_XNY.equals(buOrgCd) && !(BaseConstant.IS_YESNO_YES == isInsBiz))){
				InsRouteBscInfoVO insRouteBscInfoVO = this.insRouteBscInfoService.searchListByPrjId(Long.valueOf(prjId));
				logger.info("toAddNewEngeryPage获取路由信息.查询路由数据结果insRouteBscInfoVO：{}",JSON.toJSONString(insRouteBscInfoVO));
				List<InsRoutePrpsFeeVO> insRoutePrpsFeeVOList = new ArrayList<InsRoutePrpsFeeVO>();
				if(insRouteBscInfoVO != null){
					quatPrps.setLsPd(insRouteBscInfoVO.getLsPd());
					view.addObject("isBp", insRouteBscInfoVO.getIsBp());//是否包牌
					view.addObject("annIntRatePct", insRouteBscInfoVO.getAnnIntRatePct());//租赁年利率
					insRoutePrpsFeeVOList = insRouteBscInfoVO.getInsRoutePrpsFeeVOList();
				}
				List<InsRoutePrdInfoVO> insRoutePrdInfoVOList = insRouteBscInfoVO.getInsRoutePrdInfoVOList();
				Double mediationFeeAmtSum = 0d;
				if(CollectionUtils.isNotEmpty(insRoutePrdInfoVOList)){
					for (InsRoutePrdInfoVO insRoutePrdInfoVO : insRoutePrdInfoVOList) {
						mediationFeeAmtSum += DecimalUtils.convertFenToYuan(insRoutePrdInfoVO.getMediationFeeAmt()*insRoutePrdInfoVO.getPrdQty());

					}
				}
				Double actAmt = 0d;
				boolean fee76 = false;
				for (PrjQuatPrpsCfgDVO prjQuatPrpsCfgDVO : list) {
					String feeTypCd = prjQuatPrpsCfgDVO.getFeeTypCd();
					//留购价
					if(StringUtils.isNotEmpty(feeTypCd) && PrjQuatPrpsFeeConstant.PRJ_FEE_TYP_PURCHASE.equals(feeTypCd)){
						quatRsrvPc = prjQuatPrpsCfgDVO.getFixedAmt();
						isAllowChg = prjQuatPrpsCfgDVO.getIsAllowChg();
					}
					if(PrjQuatPrpsFeeConstant.FEE_TYP_CD_76.equals(feeTypCd)){
						fee76 = true;
						prjQuatPrpsCfgDVO.setFixedAmt(mediationFeeAmtSum);
						if(PrjBscInfoConstant.PRJ_TYP_CD_CDDYWUL.equals(prjTypCd) || PrjBscInfoConstant.PRJ_TYP_CD_ESCJYD.equals(prjTypCd) || PrjBscInfoConstant.PRJ_TYP_CD_OWNJYD.equals(prjTypCd)){
							prjQuatPrpsCfgDVO.setCntWayCd(PrjQuatPrpsConstant.CODE_PRJ_QUAT_CNT_WAY_CONT);
							prjQuatPrpsCfgDVO.setCntWayCdNm("计入合同额");
							prjQuatPrpsCfgDVO.setIsAllowChg(BaseConstant.IS_YESNO_NO);
						}else{
							prjQuatPrpsCfgDVO.setCntWayCd(PrjQuatPrpsConstant.CODE_PRJ_QUAT_CNT_WAY_OTH);
							prjQuatPrpsCfgDVO.setCntWayCdNm("其他费用");
						}
						prjQuatPrpsCfgDVO.setIsFixedAmt(BaseConstant.IS_YESNO_YES);
						prjQuatPrpsCfgDVO.setIsFixedAmtNm("是");
					}
					if(StringUtils.isNotEmpty(feeTypCd)
							&& (PrjQuatPrpsFeeConstant.FEE_TYP_CD_01.equals(feeTypCd)
							|| PrjQuatPrpsFeeConstant.FEE_TYP_CD_02.equals(feeTypCd)
							|| PrjQuatPrpsFeeConstant.FEE_TYP_CD_63.equals(feeTypCd)
							|| PrjQuatPrpsFeeConstant.FEE_TYP_CD_64.equals(feeTypCd))){
						if(CollectionUtils.isNotEmpty(insRoutePrpsFeeVOList)){
							for (InsRoutePrpsFeeVO insRoutePrpsFeeVO : insRoutePrpsFeeVOList) {
								if(PrjQuatPrpsFeeConstant.FEE_TYP_CD_01.equals(insRoutePrpsFeeVO.getFeeTypCd())){
									actAmt = insRouteBscInfoVO.getContAmt() - insRoutePrpsFeeVO.getFeeAmt();
								}
							}
							for (InsRoutePrpsFeeVO insRoutePrpsFeeVO : insRoutePrpsFeeVOList) {
								if(feeTypCd.equals(insRoutePrpsFeeVO.getFeeTypCd())){
									if(null!=insRoutePrpsFeeVO.getFeeAmt()){
										prjQuatPrpsCfgDVO.setFixedAmt(DecimalUtils.convertFenToYuan(insRoutePrpsFeeVO.getFeeAmt().longValue()));
									}
									if(null!=insRoutePrpsFeeVO.getFeePct() && insRoutePrpsFeeVO.getFeePct().doubleValue() != 0){
										prjQuatPrpsCfgDVO.setFeePct(insRoutePrpsFeeVO.getFeePct());
									}
									if(null!=insRoutePrpsFeeVO.getCntWayCd()){
										prjQuatPrpsCfgDVO.setCntWayCd(insRoutePrpsFeeVO.getCntWayCd());
									}
									if(null!=insRoutePrpsFeeVO.getIsFixedAmt()){
										prjQuatPrpsCfgDVO.setIsFixedAmt(insRoutePrpsFeeVO.getIsFixedAmt());
									}
									if(PrjQuatPrpsFeeConstant.FEE_TYP_CD_02.equals(feeTypCd)){
										if(StringUtils.isNotBlank(insRoutePrpsFeeVO.getCalBaseCd())
												&& !((insRoutePrpsFeeVO.getCalBaseCd()).equals(prjQuatPrpsCfgDVO.getCalBaseCd()))){
											if(PrjQuatPrpsConstant.CODE_CAL_BASE_CONTRACT.equals(prjQuatPrpsCfgDVO.getCalBaseCd())){
												if(null!=insRoutePrpsFeeVO.getFeeAmt()){
													prjQuatPrpsCfgDVO.setFeePct(DecimalUtils.div(insRoutePrpsFeeVO.getFeeAmt(),insRouteBscInfoVO.getContAmt(),10)*100);
												}
											}else if(PrjQuatPrpsConstant.CODE_CAL_BASE_FINANCING.equals(prjQuatPrpsCfgDVO.getCalBaseCd())){
												prjQuatPrpsCfgDVO.setFeePct(DecimalUtils.div(insRoutePrpsFeeVO.getFeeAmt(),actAmt,10)*100);
											}
                                            view.addObject("insRouteInfo", "由于该报价方案客户保证金计算基数与资管路由不一致，系统已重新推算比例值");
										}
									}
								}
							}
						}
					}
				}
				if(mediationFeeAmtSum != 0 && !fee76){
					PrjQuatPrpsCfgDVO prjQuatPrpsCfgDVO = new PrjQuatPrpsCfgDVO();
					prjQuatPrpsCfgDVO.setPrpsCfgId(list.get(0).getPrpsCfgId());
					prjQuatPrpsCfgDVO.setFeeTypCd(PrjQuatPrpsFeeConstant.FEE_TYP_CD_76);
					prjQuatPrpsCfgDVO.setFeeTypCdNm("调节费");
					prjQuatPrpsCfgDVO.setIsAllowChg(BaseConstant.IS_YESNO_YES);
					prjQuatPrpsCfgDVO.setIsAllowChgNm("是");
					prjQuatPrpsCfgDVO.setIsSysDef(BaseConstant.IS_YESNO_NO);
					prjQuatPrpsCfgDVO.setIsSysDefNm("否");
					prjQuatPrpsCfgDVO.setFixedAmt(mediationFeeAmtSum);
					if(PrjBscInfoConstant.PRJ_TYP_CD_CDDYWUL.equals(prjTypCd) || PrjBscInfoConstant.PRJ_TYP_CD_ESCJYD.equals(prjTypCd) || PrjBscInfoConstant.PRJ_TYP_CD_OWNJYD.equals(prjTypCd)){
						prjQuatPrpsCfgDVO.setCntWayCd(PrjQuatPrpsConstant.CODE_PRJ_QUAT_CNT_WAY_CONT);
						prjQuatPrpsCfgDVO.setCntWayCdNm("计入合同额");
						prjQuatPrpsCfgDVO.setIsAllowChg(BaseConstant.IS_YESNO_NO);
					}else{
						prjQuatPrpsCfgDVO.setCntWayCd(PrjQuatPrpsConstant.CODE_PRJ_QUAT_CNT_WAY_OTH);
						prjQuatPrpsCfgDVO.setCntWayCdNm("其他费用");
					}
					prjQuatPrpsCfgDVO.setIsFixedAmt(BaseConstant.IS_YESNO_YES);
					prjQuatPrpsCfgDVO.setIsFixedAmtNm("是");
					list.add(prjQuatPrpsCfgDVO);
				}
			}
				if(CollectionUtils.isNotEmpty(list)){
					for (PrjQuatPrpsCfgDVO cfgDVO : list) {
						if(cfgDVO.getFeeTypCd().equals(PrjQuatPrpsFeeConstant.FEE_TYP_CD_48)){
							loadAmt = cfgDVO.getFixedAmt()==null?0:cfgDVO.getFixedAmt();
						}
					}
				}
		}
		PrjPrdBscInfoQueryCondition prdQc = new PrjPrdBscInfoQueryCondition();
		if(StringUtils.isNotBlank(prjId)){
			prdQc.setPrjId(Long.valueOf(prjId));
			prdList=	this.prjPrdBscInfoService.searchList(prdQc);
			if(CollectionUtils.isNotEmpty(prdList)){
				prjPrdId = prdList.get(0).getId();
				for (PrjPrdBscInfoVO prjPrdBscInfoVO : prdList) {
					//资管项目、报价方案配置留购价不可变更、留购价与项目产品留购价不一致提示校验信息
					if(prjBscInfoVO.getIsInsBiz().equals(BaseConstant.IS_YESNO_YES) && isAllowChg == BaseConstant.IS_YESNO_NO && !prjPrdBscInfoVO.getRsrvPc().equals(quatRsrvPc)){
						throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"该资方要求留购价为固定"+ DecimalUtils.convertFenToYuan(Long.valueOf(String.valueOf(quatRsrvPc))) + "元/台，请在项目产品信息中修改！");
					}
					totalPrdAmt += DecimalUtils.mul(prjPrdBscInfoVO.getGuidePc(), prjPrdBscInfoVO.getPrdQty());
					totalRsrvPc +=DecimalUtils.mul(prjPrdBscInfoVO.getRsrvPc(), prjPrdBscInfoVO.getPrdQty());
				}
			}
		}
		BigDecimal bd = new BigDecimal(totalPrdAmt);
		String totalPrdAmtStr = bd.toPlainString();
		Integer isShowAdd = BaseConstant.IS_YESNO_NO;
		if(prjBscInfoVO.getBuOrgCd().equals(PrjBscInfoConstant.CODE_BU_ORG_CD_XNY)&&!prjTypCd.equals(PrjBscInfoConstant.PRJ_TYP_CD_XSHZ)){
			//判断是否可以重新生成方案信息
				isShowAdd =  BaseConstant.IS_YESNO_YES;
		}
		BigDecimal rsrvPc = new BigDecimal(DecimalUtils.convertFenToYuan(new Double(totalRsrvPc).longValue()));
		String totalRsrvPcStr = rsrvPc.toPlainString();
		//根据id查询修改数据
		if(StringUtils.isNotBlank(id)){
			//查询已经保存的报价方案
			PrjQuatPrpsVO prjQuatPrps = this.prjQuatPrpsService.selectById(Long.valueOf(id));
			double actAmt = 0d;//直租补录时间放款金额，补录结束去除
			PrjPrdPaySchMQueryCondition qCond = new PrjPrdPaySchMQueryCondition();
			qCond.setPrjId(Long.valueOf(prjId));
            qCond.setPaySchTypCd(PrjPrdPaySchMConstant.PAY_SCH_TYP_CD_WS);
			List<PrjPrdPaySchMVO> schMList = this.prjPrdPaySchMService.searchList(qCond);
			if(CollectionUtils.isNotEmpty(schMList)){
				for (PrjPrdPaySchMVO prjPrdPaySchMVO : schMList) {
					if(null!=prjPrdPaySchMVO.getThdPayAmt()){
						actAmt = DecimalUtils.add(actAmt, prjPrdPaySchMVO.getThdPayAmt());
					}
				}
			}
			prjQuatPrps.setTempActLsAmt(actAmt);
			ListPageVO<PrjQuatPrpsPaySchVO> payListPage = new ListPageVO<PrjQuatPrpsPaySchVO>(prjQuatPrps.getPrjQuatPrpsPaySchList(),prjQuatPrps.getPrjQuatPrpsPaySchList().size());
			prjQuatPrps.setPrjQuatPrpsPaySchPage(payListPage);
			ListPageVO<PrjQuatPrpsFeeVO> detailListPage = new ListPageVO<PrjQuatPrpsFeeVO>(prjQuatPrps.getPrjQuatPrpsFeelist(),prjQuatPrps.getPrjQuatPrpsFeelist().size());
			prjQuatPrps.setPrjQuatPrpsFeePage(detailListPage);
			view.addObject("detailListPage", JSON.toJSONString(detailListPage));
			view.addObject("payListPage", JSON.toJSONString(payListPage));
			view.addObject("prjQuatPrps", JSON.toJSONString(prjQuatPrps));
            view.addObject("cstIrr", prjQuatPrps.getCstIrr());
			prpsTypCd = prjQuatPrps.getPrpsTypCd();
		}
		view.addObject("id", id);
		view.addObject("isShowAdd", isShowAdd);
		//租赁期数单位
		List<KeyValueVO> lsPdUntCdList = this.prjQuatPrpsCfgMService.searchLsPdUntCdList();
		view.addObject("lsPdUntCdList", lsPdUntCdList);
		//支付方式
		List<KeyValueVO> payWayCdList = this.prjBscInfoService.getKeyValueList(DictionaryConstant.CODE_PRJ_QUAT_PAY_WAY_CD,CurrentThreadContext.getCurrentSysCd(),prjBscInfoVO.getCstMgrOrgCd());
		/*List<KeyValueVO> payWayCdList = this.prjQuatPrpsCfgMService.searchPayWayCdList();*/
		view.addObject("payWayCdList", payWayCdList);
		//保证金处理方式
		List<KeyValueVO> dpstHdlWayCdList = this.prjQuatPrpsCfgMService.searchDpstHdlWayCdList();
		view.addObject("dpstHdlWayCdList", dpstHdlWayCdList);
		//租赁期满处理方式
		List<KeyValueVO> expHdlWayCdList = this.prjQuatPrpsCfgMService.searchExpHdlWayCdList();
		view.addObject("expHdlWayCdList", expHdlWayCdList);
		//不还款处理方式
		List<KeyValueVO> noPayWayCdList = this.prjBscInfoService.searchNoPayWayCdList();
		view.addObject("noPayWayCdList", noPayWayCdList);
		//费用类型
		JSONArray feeTypCdListJSON = this.prjQuatPrpsCfgMService.searchFeeTypCdList();
		view.addObject("feeTypCdListJSON", feeTypCdListJSON);
		//费用计算基数
		List<KeyValueVO> calBaseCdList = this.prjQuatPrpsCfgMService.searchCalBaseCdList();
		view.addObject("calBaseCdListJSON", JSON.toJSONString(calBaseCdList));
		List<KeyValueVO> yesNoCdList = this.prjQuatPrpsCfgMService.searchYesOrNoCdList();
		view.addObject("yesOrNoCdListJSON",JSON.toJSONString(yesNoCdList) );
		//费用计入方式
		List<KeyValueVO> cntWayCdList = this.prjQuatPrpsCfgMService.searchCntWayCdList();
		//计算方式
		List<KeyValueVO> lsCalWayCdList = this.prjBscInfoService.searchLsCalWayCdList();
		//租赁年利率计算方式
		List<KeyValueVO> intRateWayCdList = this.prjBscInfoService.searchIntRateWayCdList();
		//拆分比例
		List<KeyValueVO> prjQuatSplitPctList = this.prjBscInfoService.getKeyValueList(DictionaryConstant.CODE_QUAT_SPLIT_CD,CurrentThreadContext.getCurrentSysCd(),prjBscInfoVO.getCstMgrOrgCd());
		/*List<KeyValueVO> prjQuatSplitPctList = this.prjBscInfoService.getPrjQuatSplitPctList();*/

		//专车客车从咨询费1拆分出来的供应商比例
		List<KeyValueVO> prjConsSplitPctList = this.prjBscInfoService.getPrjConsSplitPctList();

        //是否包牌下拉列表
        List<KeyValueVO> isBpList = this.sysDictionaryApiService.getKvList(DictionaryConstant.CODE_IS_BP_LIST_CD,CurrentThreadContext.getCurrentSysCd() , prjBscInfoVO.getCstMgrOrgCd());

        Map<String,String>  scaleNumMap  =  this.prjQuatPrpsService.getDecimalDigitsByBuOrgCodeNew(prjBscInfoVO.getCstMgrOrgCd());
        view.addObject("isBpList", isBpList);
		view.addObject("cntWayCdListJSON", JSON.toJSONString(cntWayCdList));
		view.addObject("prjId", prjId);
		view.addObject("prjConsSplitPctList", JSON.toJSONString(prjConsSplitPctList));
		view.addObject("quatPrps", quatPrps);//配置方案信息
		view.addObject("quatPrpsJson", quatPrps==null?"": JSON.toJSONString(quatPrps));//配置方案信息
		view.addObject("PrjQuatPrpsCfgDetailList", list);//配置明细信息
		view.addObject("lsPdUntCdList", lsPdUntCdList);//租赁期数单位
		view.addObject("payWayCdList", payWayCdList);//支付方式
		view.addObject("lsCalWayCdList", lsCalWayCdList);//计算方式
		view.addObject("calBaseCdList", calBaseCdList);//费用计算基数
		view.addObject("cntWayCdList", cntWayCdList);///费用计入方式
		view.addObject("intRateWayCdList", intRateWayCdList);//租赁年利率计算方式
		view.addObject("dpstHdlWayCdList", dpstHdlWayCdList);//客户保证金处理方式
		view.addObject("expHdlWayCdList", expHdlWayCdList);//租赁期满处理方式
		view.addObject("prdNum", prdNum);//产品数量
		view.addObject("totalPrdAmt",totalPrdAmtStr);
		view.addObject("totalRsrvPcStr",totalRsrvPcStr);//留购价总金额
		view.addObject("detailFlag",detailFlag);
		view.addObject("prpsCfgId", prpsCfgId);
		view.addObject("scaleNumMap", scaleNumMap.isEmpty()==true?"":JSON.toJSONString(scaleNumMap));
		view.addObject("prpsTypCd", prpsTypCd);
		view.addObject("prjQuatSplitPctList", prjQuatSplitPctList);
		view.addObject("insuTotalAmt", insuTotalAmt);
		view.addObject("purchTax", purchTax);
		view.addObject("buOrgCd", buOrgCd);
		view.addObject("initLsPct", initLsPct);
		view.addObject("prjCstMgrOrgCd", prjCstMgrOrgCd);
		view.addObject("loadAmt", loadAmt);
		view.addObject("insCode",null==prjBscInfoVO.getInsCode()?"":prjBscInfoVO.getInsCode());
		view.addObject("prjTypCd", null== prjTypCd ?"": prjTypCd);
        view.addObject("bizTypCd", null==prjBscInfoVO.getBizTypCd()?"":prjBscInfoVO.getBizTypCd());
		return view;
	}
	/**
	 * 处理浙商转我司数据
	 */
	@RequestMapping(value = "/dealZSChangeOurData.do", method = { RequestMethod.POST })
	@ResponseBody
	public Object dealZSChangeOurData(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_ADD_SUCC);
		try {
		   this.prjQuatPrpsService.modifyDealZSChangeOurData();
			result.setData("");
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			logger.error("处理浙商转我司数据发生异常,msg:{}",ex.getMessage());
		}catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			logger.error("处理浙商转我司数据发生异常,msg:{}",ex.getMessage());
		}

		return result;
	}
	/**
	 * 处理浦发转我司数据
	 */
	@RequestMapping(value = "/dealPFChangeOurData.do", method = { RequestMethod.POST })
	@ResponseBody
	public Object dealPFChangeOurData(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_ADD_SUCC);
		try {
		   this.prjQuatPrpsZGService.modifyDealPFHistoryData();
			result.setData("");
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			logger.error("处理浦发转我司数据发生异常,msg:{}",ex.getMessage());
		}catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			logger.error("处理浦发转我司数据发生异常msg:{}",ex.getMessage());
		}

		return result;
	}
	
	/**
	 * 处理网商转我司数据
	 */
	@RequestMapping(value = "/dealWSChangeOurData.do", method = { RequestMethod.POST })
	@ResponseBody
	public Object dealWSChangeOurData(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_ADD_SUCC);
		try {
		   this.prjQuatPrpsZGService.modifyDealWSHistoryData();
			result.setData("");
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			logger.error("处理网商转我司数据发生异常，msg:{}",ex.getMessage());
		}catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			logger.error("处理网商转我司数据发生异常:{}",ex.getMessage());
		}

		return result;
	}
	
	/**
	 * 处理资管转我司（我司支付表）还款日信息
	 */
	@RequestMapping(value = "/modifyDealZGPayDtData.do", method = { RequestMethod.POST })
	@ResponseBody
	public Object modifyDealZGPayDtData(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_ADD_SUCC);
		try {
		   this.prjQuatPrpsZGService.modifyDealZGPayDtData();
			result.setData("");
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			logger.error("修改历史数据资方转我司(我司支付表)还款日信息发生异常:msg:{}",ex.getMessage());
		}catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			logger.error("修改历史数据资方转我司(我司支付表)还款日信息发生异常:msg:{}",ex.getMessage());
		}

		return result;
	}

    /**
     *处理历史浙银数据，导出异常合同号
     */
    @SuppressWarnings("unchecked")
    @RequestMapping(value = "/dealZYHisData.do", method = { RequestMethod.POST})
    @ResponseBody
    public DataResultVO  dealZYHisData(HttpServletRequest request, HttpServletResponse response) {
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_DELETE_SUCC);
        try {
			result =   this.prjQuatPrpsService.modifyDealZYHistoryData();
			logger.info("处理历史浙银数据result:{}",JSON.toJSONString(result));
        }catch (BaseException ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(ex.getMessage());
            logger.error("处理历史浙银数据发生异常:msg:{}",ex.getMessage());

        }catch (Exception ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			logger.error("处理历史浙银数据发生异常:msg:{}",ex.getMessage());
        }
        return result;
    }
    /**
     *处理浙银转我司数据
     */
    @SuppressWarnings("unchecked")
    @RequestMapping(value = "/dealZYChangeOurData.do", method = { RequestMethod.POST})
    @ResponseBody
    public DataResultVO  dealZYChangeOurData(HttpServletRequest request, HttpServletResponse response) {
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_DELETE_SUCC);
        try {
            this.prjQuatPrpsZGService.modifyDealZYChangeOurData();
			logger.info("处理浙银转我司数据");
        }catch (BaseException ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(ex.getMessage());
			logger.error("处理浙银转我司数据发生异常:msg:{}",ex.getMessage());
        }catch (Exception ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			logger.error("处理浙银转我司数据发生异常:msg:{}",ex.getMessage());
        }
        return result;
    }
    /**
     * 导出核查数据处理结果
     */
    @SuppressWarnings("unchecked")
    @RequestMapping(value = "/exportCheckData.do", method = {RequestMethod.POST})
    @ResponseBody
    public DataResultVO exportCheckData(HttpServletRequest request, HttpServletResponse response) {
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_DELETE_SUCC);
        try {
            result = this.prjQuatPrpsZGService.exportCheckChangeOurDataResult();
			logger.info("导出核查数据处理结果result:{}",JSON.toJSONString(result));
        } catch (BaseException ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(ex.getMessage());
			logger.error("导出核查数据处理结果错误:msg:{}",ex.getMessage());
        } catch (Exception ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			logger.error("导出核查数据处理结果错误:msg:{}",ex.getMessage());
        }
        return result;
    }

    /**
     * 初始化列表
     */
    @SuppressWarnings("unchecked")
    @RequestMapping(value = "/prjQuatPrpsCfgDInitList.do", method = { RequestMethod.GET})
    @ResponseBody
    public Object prjQuatPrpsCfgDInitList(HttpServletRequest request, HttpServletResponse response) {
        String currentPage = request.getParameter("page");
        String pageSize = request.getParameter("pagesize");
        String prpsCfgId = request.getParameter("prpsCfgId");
        String prjId = request.getParameter("prjId");
        Pager page = new Pager();
        if (StringUtils.isNotEmpty(currentPage)) {
            page.setCurrentPage(Integer.parseInt(currentPage));
        }

        if (StringUtils.isNotEmpty(currentPage)) {
            page.setEveryPage(Integer.parseInt(pageSize));
        }

        PrjQuatPrpsCfgDQueryCondition qc = new PrjQuatPrpsCfgDQueryCondition();
        page.setEveryPage(Integer.MAX_VALUE);//最大数据量
        ListPageVO<PrjQuatPrpsCfgDVO> listPage = null;
        if (StringUtils.isNotEmpty(prpsCfgId)) {	//如果有方案配置ID 直接查询此方案配置的相关费用信息
            qc.setPrpsCfgId(Long.valueOf(prpsCfgId));
            page.setCondition(qc);
            Pager pager = this.prjQuatPrpsCfgDService.searchListPage(page);
            List<PrjQuatPrpsCfgDVO> list = (List<PrjQuatPrpsCfgDVO>) pager.getResultList();
            List<SysDictionaryDTO> sysDictionaryDTOList = this.sysDictionaryApiService.searchGroup(CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd(), DictionaryConstant.CODE_PRJ_QUAT_FEE_TYP_CD);
            if(CollectionUtils.isNotEmpty(list)){
                for (PrjQuatPrpsCfgDVO prjQuatPrpsCfgDVO : list) {
                    String feeTypCd = prjQuatPrpsCfgDVO.getFeeTypCd();//费用类型代码 如果此费用类型在数据字典里是系统内置的 则设置flag标识
                    for (SysDictionaryDTO sysDictionaryDTO : sysDictionaryDTOList) {
                        String code = sysDictionaryDTO.getCode();
                        if(code.equals(feeTypCd)){
                            if(sysDictionaryDTO.getIsSysDef().equals(BaseConstant.IS_YESNO_YES)){
                                prjQuatPrpsCfgDVO.setFlag(BaseConstant.IS_YESNO_YES);
                                prjQuatPrpsCfgDVO.setFlagNm(BaseConstant.IS_YESNO_YES_NM);
                            }
                        }
                    }
                    //处理费用金额
                    if(null!=prjQuatPrpsCfgDVO.getFixedAmt()){
                        prjQuatPrpsCfgDVO.setFixedAmt(DecimalUtils.div(prjQuatPrpsCfgDVO.getFixedAmt(), 100));
                    }
                }
               PrjBscInfoVO prjBscInfoVO =  this.prjBscInfoService.selectById(Long.valueOf(prjId));
				String prjTypCd = prjBscInfoVO.getPrjTypCd();
				if(null!=prjBscInfoVO.getCalId()){
                   CalQuatPrpsVO calQuatPrps = this.calQuatPrpsService.selectCalQuatProsAndDetailById(prjBscInfoVO.getCalId());
                    List<CalQuatPrpsFeeVO>  feeList = calQuatPrps.getFeeList();
                    if(CollectionUtils.isNotEmpty(feeList)){
                        //设置报价器的数据为只读
                        for (PrjQuatPrpsCfgDVO prjQuatPrpsCfgDVO : list) {
                            for (CalQuatPrpsFeeVO feeVO : feeList) {
                                if(prjQuatPrpsCfgDVO.getFeeTypCd().equals(feeVO.getFeeTypCd())){
                                    if(null!=feeVO.getFeeAmt()){
                                        prjQuatPrpsCfgDVO.setFixedAmt(feeVO.getFeeAmt());
                                    }
                                    if(null!=feeVO.getFeePct()){
                                        prjQuatPrpsCfgDVO.setFeePctMax(feeVO.getFeePct());
                                        prjQuatPrpsCfgDVO.setFeePctMin(feeVO.getFeePct());
                                    }
                                    if(null!=feeVO.getCntWayCd()){
                                        prjQuatPrpsCfgDVO.setCntWayCd(feeVO.getCntWayCd());
                                    }
                                    if(null!=feeVO.getCalBaseCd()){
                                        prjQuatPrpsCfgDVO.setCalBaseCd(feeVO.getCalBaseCd());
                                    }
                                    if(null!=feeVO.getIsFixedAmt()){
                                        prjQuatPrpsCfgDVO.setIsFixedAmt(feeVO.getIsFixedAmt());
                                    }
                                    prjQuatPrpsCfgDVO.setIsAllowChg(BaseConstant.IS_YESNO_NO);
                                    prjQuatPrpsCfgDVO.setIsSysDef(BaseConstant.IS_YESNO_YES);
                                    break;
                                }
                            }
                        }
						/**
						 * 发票金额特殊处理
						 */
						for (CalQuatPrpsFeeVO calQuatPrpsFeeVO : feeList) {
							if(PrjQuatPrpsFeeConstant.FEE_TYP_CD_63.equals(calQuatPrpsFeeVO.getFeeTypCd())){
								boolean has63 = false;
								for (PrjQuatPrpsCfgDVO prjQuatPrpsCfgDVO : list) {
									if(PrjQuatPrpsFeeConstant.FEE_TYP_CD_63.equals(prjQuatPrpsCfgDVO.getFeeTypCd())){
										if(null!=calQuatPrpsFeeVO.getFeeAmt()){
											prjQuatPrpsCfgDVO.setFixedAmt(calQuatPrpsFeeVO.getFeeAmt());
										}
										if(null!=calQuatPrpsFeeVO.getFeePct()){
											prjQuatPrpsCfgDVO.setFeePctMax(calQuatPrpsFeeVO.getFeePct());
											prjQuatPrpsCfgDVO.setFeePctMin(calQuatPrpsFeeVO.getFeePct());
										}
										if(null!=calQuatPrpsFeeVO.getCntWayCd()){
											prjQuatPrpsCfgDVO.setCntWayCd(calQuatPrpsFeeVO.getCntWayCd());
										}
										if(null!=calQuatPrpsFeeVO.getCalBaseCd()){
											prjQuatPrpsCfgDVO.setCalBaseCd(calQuatPrpsFeeVO.getCalBaseCd());
										}
										if(null!=calQuatPrpsFeeVO.getIsFixedAmt()){
											prjQuatPrpsCfgDVO.setIsFixedAmt(calQuatPrpsFeeVO.getIsFixedAmt());
										}
										prjQuatPrpsCfgDVO.setIsAllowChg(BaseConstant.IS_YESNO_NO);
										prjQuatPrpsCfgDVO.setIsSysDef(BaseConstant.IS_YESNO_YES);
										has63 = true;
									}
								}
								if(!has63){
									PrjQuatPrpsCfgDVO prjQuatPrpsCfgDVO = new PrjQuatPrpsCfgDVO();
									if(null!=calQuatPrpsFeeVO.getFeeAmt()){
										prjQuatPrpsCfgDVO.setFixedAmt(calQuatPrpsFeeVO.getFeeAmt());
									}
									if(null!=calQuatPrpsFeeVO.getFeePct()){
										prjQuatPrpsCfgDVO.setFeePctMax(calQuatPrpsFeeVO.getFeePct());
										prjQuatPrpsCfgDVO.setFeePctMin(calQuatPrpsFeeVO.getFeePct());
									}
									if(null!=calQuatPrpsFeeVO.getCntWayCd()){
										prjQuatPrpsCfgDVO.setCntWayCd(calQuatPrpsFeeVO.getCntWayCd());
									}
									if(null!=calQuatPrpsFeeVO.getCalBaseCd()){
										prjQuatPrpsCfgDVO.setCalBaseCd(calQuatPrpsFeeVO.getCalBaseCd());
									}
									if(null!=calQuatPrpsFeeVO.getIsFixedAmt()){
										prjQuatPrpsCfgDVO.setIsFixedAmt(calQuatPrpsFeeVO.getIsFixedAmt());
									}
									prjQuatPrpsCfgDVO.setCntWayCdNm(calQuatPrpsFeeVO.getCntWayCdNm());
									prjQuatPrpsCfgDVO.setIsFixedAmtNm(calQuatPrpsFeeVO.getIsFixedAmtNm());
									prjQuatPrpsCfgDVO.setIsAllowChg(BaseConstant.IS_YESNO_NO);
									prjQuatPrpsCfgDVO.setIsSysDef(BaseConstant.IS_YESNO_YES);
									prjQuatPrpsCfgDVO.setFeeTypCd(PrjQuatPrpsFeeConstant.FEE_TYP_CD_63);
									prjQuatPrpsCfgDVO.setFeeTypCdNm("发票金额");
									list.add(prjQuatPrpsCfgDVO);
								}
							}
						}
                    }
                }
				logger.info("prjQuatPrpsCfgDInitList方案费用项初始化.路由前结果list:{}",JSON.toJSONString(list));
				Integer isInsBiz = prjBscInfoVO.getIsInsBiz();
				if(!(PrjBscInfoConstant.CODE_BU_ORG_CD_XNY.equals(CurrentThreadContext.getCurrentBuOrgCd()) && !(BaseConstant.IS_YESNO_YES == isInsBiz))){
					InsRouteBscInfoVO insRouteBscInfoVO = this.insRouteBscInfoService.searchListByPrjId(Long.valueOf(prjId));
					logger.info("prjQuatPrpsCfgDInitList获取路由信息.查询路由数据结果insRouteBscInfoVO:{}", JSON.toJSONString(insRouteBscInfoVO));
					List<InsRoutePrpsFeeVO> insRoutePrpsFeeVOList = new ArrayList<InsRoutePrpsFeeVO>();
					if(insRouteBscInfoVO != null){
						insRoutePrpsFeeVOList = insRouteBscInfoVO.getInsRoutePrpsFeeVOList();
					}
					List<InsRoutePrdInfoVO> insRoutePrdInfoVOList = insRouteBscInfoVO.getInsRoutePrdInfoVOList();
					Double mediationFeeAmtSum = 0d;
					if(CollectionUtils.isNotEmpty(insRoutePrdInfoVOList)){
						for (InsRoutePrdInfoVO insRoutePrdInfoVO : insRoutePrdInfoVOList) {
							mediationFeeAmtSum += DecimalUtils.convertFenToYuan(insRoutePrdInfoVO.getMediationFeeAmt()*insRoutePrdInfoVO.getPrdQty());

						}
					}
					Double actAmt = 0d;
					boolean fee76 = false;
					for (PrjQuatPrpsCfgDVO prjQuatPrpsCfgDVO : list) {
						String feeTypCd = prjQuatPrpsCfgDVO.getFeeTypCd();
						if(PrjQuatPrpsFeeConstant.FEE_TYP_CD_76.equals(feeTypCd)){
							fee76 = true;
							prjQuatPrpsCfgDVO.setFixedAmt(mediationFeeAmtSum);
							if(PrjBscInfoConstant.PRJ_TYP_CD_CDDYWUL.equals(prjTypCd) || PrjBscInfoConstant.PRJ_TYP_CD_ESCJYD.equals(prjTypCd) || PrjBscInfoConstant.PRJ_TYP_CD_OWNJYD.equals(prjTypCd)){
								prjQuatPrpsCfgDVO.setCntWayCd(PrjQuatPrpsConstant.CODE_PRJ_QUAT_CNT_WAY_CONT);
								prjQuatPrpsCfgDVO.setCntWayCdNm("计入合同额");
								prjQuatPrpsCfgDVO.setIsAllowChg(BaseConstant.IS_YESNO_NO);
							}else{
								prjQuatPrpsCfgDVO.setCntWayCd(PrjQuatPrpsConstant.CODE_PRJ_QUAT_CNT_WAY_OTH);
								prjQuatPrpsCfgDVO.setCntWayCdNm("其他费用");
							}
							prjQuatPrpsCfgDVO.setIsFixedAmt(BaseConstant.IS_YESNO_YES);
							prjQuatPrpsCfgDVO.setIsFixedAmtNm("是");
						}
						if(StringUtils.isNotEmpty(feeTypCd)
								&& (PrjQuatPrpsFeeConstant.FEE_TYP_CD_01.equals(feeTypCd)
								|| PrjQuatPrpsFeeConstant.FEE_TYP_CD_02.equals(feeTypCd)
								|| PrjQuatPrpsFeeConstant.FEE_TYP_CD_63.equals(feeTypCd)
								|| PrjQuatPrpsFeeConstant.FEE_TYP_CD_64.equals(feeTypCd))){
							if(CollectionUtils.isNotEmpty(insRoutePrpsFeeVOList)){
								for (InsRoutePrpsFeeVO insRoutePrpsFeeVO : insRoutePrpsFeeVOList) {
									if(PrjQuatPrpsFeeConstant.FEE_TYP_CD_01.equals(insRoutePrpsFeeVO.getFeeTypCd())){
										actAmt = insRouteBscInfoVO.getContAmt() - insRoutePrpsFeeVO.getFeeAmt();
									}
								}
								for (InsRoutePrpsFeeVO insRoutePrpsFeeVO : insRoutePrpsFeeVOList) {
									if(feeTypCd.equals(insRoutePrpsFeeVO.getFeeTypCd())){
										if(null!=insRoutePrpsFeeVO.getFeeAmt()){
											prjQuatPrpsCfgDVO.setFixedAmt(DecimalUtils.convertFenToYuan(insRoutePrpsFeeVO.getFeeAmt().longValue()));
										}
										if(null!=insRoutePrpsFeeVO.getFeePct() && insRoutePrpsFeeVO.getFeePct().doubleValue() != 0){
											prjQuatPrpsCfgDVO.setFeePct(insRoutePrpsFeeVO.getFeePct());
										}
										if(null!=insRoutePrpsFeeVO.getCntWayCd()){
											prjQuatPrpsCfgDVO.setCntWayCd(insRoutePrpsFeeVO.getCntWayCd());
										}
										if(null!=insRoutePrpsFeeVO.getIsFixedAmt()){
											prjQuatPrpsCfgDVO.setIsFixedAmt(insRoutePrpsFeeVO.getIsFixedAmt());
										}
										prjQuatPrpsCfgDVO.setIsRoute(BaseConstant.IS_YESNO_YES);
										if(PrjQuatPrpsFeeConstant.FEE_TYP_CD_02.equals(feeTypCd)){
											if(StringUtils.isNotBlank(insRoutePrpsFeeVO.getCalBaseCd())
													&& !((insRoutePrpsFeeVO.getCalBaseCd()).equals(prjQuatPrpsCfgDVO.getCalBaseCd()))){
												if(PrjQuatPrpsConstant.CODE_CAL_BASE_CONTRACT.equals(prjQuatPrpsCfgDVO.getCalBaseCd())){
													if(null!=insRoutePrpsFeeVO.getFeeAmt()){
														prjQuatPrpsCfgDVO.setFeePct(DecimalUtils.div(insRoutePrpsFeeVO.getFeeAmt(),insRouteBscInfoVO.getContAmt(),10)*100);
													}
												}else if(PrjQuatPrpsConstant.CODE_CAL_BASE_FINANCING.equals(prjQuatPrpsCfgDVO.getCalBaseCd())){
													prjQuatPrpsCfgDVO.setFeePct(DecimalUtils.div(insRoutePrpsFeeVO.getFeeAmt(),actAmt,10)*100);
												}
											}
										}
									}
								}
							}
						}
					}
					if(mediationFeeAmtSum != 0 && !fee76){
						PrjQuatPrpsCfgDVO prjQuatPrpsCfgDVO = new PrjQuatPrpsCfgDVO();
						prjQuatPrpsCfgDVO.setPrpsCfgId(list.get(0).getPrpsCfgId());
						prjQuatPrpsCfgDVO.setFeeTypCd(PrjQuatPrpsFeeConstant.FEE_TYP_CD_76);
						prjQuatPrpsCfgDVO.setFeeTypCdNm("调节费");
						prjQuatPrpsCfgDVO.setIsAllowChg(BaseConstant.IS_YESNO_YES);
						prjQuatPrpsCfgDVO.setIsAllowChgNm("是");
						prjQuatPrpsCfgDVO.setIsSysDef(BaseConstant.IS_YESNO_NO);
						prjQuatPrpsCfgDVO.setIsSysDefNm("否");
						prjQuatPrpsCfgDVO.setFixedAmt(mediationFeeAmtSum);
						if(PrjBscInfoConstant.PRJ_TYP_CD_CDDYWUL.equals(prjTypCd) || PrjBscInfoConstant.PRJ_TYP_CD_ESCJYD.equals(prjTypCd) || PrjBscInfoConstant.PRJ_TYP_CD_OWNJYD.equals(prjTypCd)){
							prjQuatPrpsCfgDVO.setCntWayCd(PrjQuatPrpsConstant.CODE_PRJ_QUAT_CNT_WAY_CONT);
							prjQuatPrpsCfgDVO.setCntWayCdNm("计入合同额");
							prjQuatPrpsCfgDVO.setIsAllowChg(BaseConstant.IS_YESNO_NO);
						}else{
							prjQuatPrpsCfgDVO.setCntWayCd(PrjQuatPrpsConstant.CODE_PRJ_QUAT_CNT_WAY_OTH);
							prjQuatPrpsCfgDVO.setCntWayCdNm("其他费用");
						}
						prjQuatPrpsCfgDVO.setIsFixedAmt(BaseConstant.IS_YESNO_YES);
						prjQuatPrpsCfgDVO.setIsFixedAmtNm("是");
						list.add(prjQuatPrpsCfgDVO);
					}
				}
            }
			logger.info("prjQuatPrpsCfgDInitList方案费用项初始化.路由后结果list:{}", JSON.toJSONString(list));
            listPage = new ListPageVO<PrjQuatPrpsCfgDVO>(list, pager.getTotalCount());
			logger.info("查询数据完成:{}",JSON.toJSONString(page));
        }
        return listPage;
    }

    /**
     * 初始化列表
     */
    @SuppressWarnings("unchecked")
    @RequestMapping(value = "/cddPrjQuatPrpsCfgDInitList.do", method = { RequestMethod.GET})
    @ResponseBody
    public Object cddPrjQuatPrpsCfgDInitList(HttpServletRequest request, HttpServletResponse response) {
        String currentPage = request.getParameter("page");
        String pageSize = request.getParameter("pagesize");
        String prpsCfgId = request.getParameter("prpsCfgId");
		String prjId = request.getParameter("prjId");//项目ID
		String editFlag = request.getParameter("editFlag") ;
		String prpsId = request.getParameter("prpsId") ;
        Pager page = new Pager();
        if (StringUtils.isNotEmpty(currentPage)) {
            page.setCurrentPage(Integer.parseInt(currentPage));
        }

        if (StringUtils.isNotEmpty(currentPage)) {
            page.setEveryPage(Integer.parseInt(pageSize));
        }

        PrjQuatPrpsCfgDQueryCondition qc = new PrjQuatPrpsCfgDQueryCondition();
        page.setEveryPage(Integer.MAX_VALUE);//最大数据量
        ListPageVO<PrjQuatPrpsCfgDVO> listPage = null;
        double firstPct = 0d;
        int prdNum = 0 ;
		/**
		 * 客户融资额
		 */
		double custFina = 0d;
		/**
		 * 车辆评估价
		 */
        double VehVal = 0d;
        PrjPrdBscInfoQueryCondition prdQc = new PrjPrdBscInfoQueryCondition();
        prdQc.setPrjId(Long.valueOf(prjId));
        List<PrjPrdBscInfoVO> prdList = this.prjPrdBscInfoService.searchList(prdQc);
        if (CollectionUtils.isNotEmpty(prdList)) {
            for (PrjPrdBscInfoVO prjPrdBscInfoVO : prdList) {
                prdNum += prjPrdBscInfoVO.getPrdQty();
                custFina += DecimalUtils.mul(prjPrdBscInfoVO.getCustFina(), prjPrdBscInfoVO.getPrdQty());
                VehVal += DecimalUtils.mul(prjPrdBscInfoVO.getVehVal(), prjPrdBscInfoVO.getPrdQty());
            }
        }
		/**
		 * TODO 如下判断车抵贷线下 和 二手车交易贷 的if 判断逻辑如果修改请注意if里面的逻辑 是否兼容
         * 内转交易贷
		 */
		PrjBscInfoVO bscInfoVO =  this.prjBscInfoService.selectById(Long.valueOf(prjId));
		String prjTypCd = bscInfoVO.getPrjTypCd();
		if((prjTypCd.equals(PrjBscInfoConstant.PRJ_TYP_CD_CDDYWUL)|| prjTypCd.equals(PrjBscInfoConstant.PRJ_TYP_CD_ESCJYD)
                || prjTypCd.equals(PrjBscInfoConstant.PRJ_TYP_CD_OWNJYD)) && bscInfoVO.getBuOrgCd().equals(PrjBscInfoConstant.CODE_BU_ORG_CD_ZK)){
			if(null==bscInfoVO.getRcCstBscInfoId()){
                throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "请先查询客户的征信信息！");
            }
			if(StringUtils.isNotEmpty(bscInfoVO.getInsCode()) && (PrjBscInfoConstant.PRJ_INS_CODE_JXFL.equals(bscInfoVO.getInsCode())
				|| PrjBscInfoConstant.PRJ_INS_CODE_XYFL.equals(bscInfoVO.getInsCode())
				|| PrjBscInfoConstant.PRJ_INS_CODE_SYFL.equals(bscInfoVO.getInsCode())
				|| PrjBscInfoConstant.PRJ_INS_CODE_TYFL.equals(bscInfoVO.getInsCode())
				|| PrjBscInfoConstant.PRJ_INS_CODE_HRBANK.equals(bscInfoVO.getInsCode())
				|| PrjBscInfoConstant.PRJ_INS_CODE_WEBANK.equals(bscInfoVO.getInsCode())
				|| PrjBscInfoConstant.PRJ_INS_CODE_CCBANK.equals(bscInfoVO.getInsCode())
				|| PrjBscInfoConstant.PRJ_INS_CODE_CCBANKTB.equals(bscInfoVO.getInsCode())
				|| PrjBscInfoConstant.PRJ_INS_CODE_JXYMBANK.equals(bscInfoVO.getInsCode())
				|| PrjBscInfoConstant.PRJ_INS_CODE_TIANJINBANK.equals(bscInfoVO.getInsCode())
				|| PrjBscInfoConstant.PRJ_INS_CODE_YLBANK.equals(bscInfoVO.getInsCode())
				|| PrjBscInfoConstant.PRJ_INS_CODE_ICBCQD.equals(bscInfoVO.getInsCode())
				|| PrjBscInfoConstant.PRJ_INS_CODE_SSFL.equals(bscInfoVO.getInsCode())
            )){
				/**
				 *  代码优化思路 车抵贷线下分为三总  1、首期比例是0的  2、首期比例按客户融资金额 与 车辆估值 进行反推的   3、首期不做限制 默认是 0
				 */
				if(prjTypCd.equals(PrjBscInfoConstant.PRJ_TYP_CD_CDDYWUL)){
                    /**
                     *  1、江西金租 、 兴业金租 ：车抵贷线下  首付比例 =  0  ,合同额 = 户融资额, 融资额等于 = 客户融资额
                     */
                    if(PrjBscInfoConstant.PRJ_INS_CODE_JXFL.equals(bscInfoVO.getInsCode())
                            || PrjBscInfoConstant.PRJ_INS_CODE_XYFL.equals(bscInfoVO.getInsCode())
                    ){
                        firstPct = 0d;
                    }
                    /**
                     * 2、三一金租 车抵贷线下业务  首付比例倒推
                     */
                    if(PrjBscInfoConstant.PRJ_INS_CODE_SYFL.equals(bscInfoVO.getInsCode())
                    ){
                        firstPct = DecimalUtils.mul(DecimalUtils.div(DecimalUtils.sub(VehVal,custFina) ,VehVal),100,15);
                    }

				}
                /**
                 * 代码优化思路  二手车交易贷 分为2中  1、首期比例按客户融资金额 与 车辆估值 进行反推的  ， 2、首期不做限制 默认是 0
                 */
                if(prjTypCd.equals(PrjBscInfoConstant.PRJ_TYP_CD_ESCJYD) || PrjBscInfoConstant.PRJ_TYP_CD_OWNJYD.equals(prjTypCd)){

                    /**
                     * 江西金租、兴业金租、三一金租、天津银行 ：首期比例按客户融资金额 与 车辆估值 进行反推
                     */
                    if(PrjBscInfoConstant.PRJ_INS_CODE_JXFL.equals(bscInfoVO.getInsCode())
                            || PrjBscInfoConstant.PRJ_INS_CODE_XYFL.equals(bscInfoVO.getInsCode())
                            || PrjBscInfoConstant.PRJ_INS_CODE_SYFL.equals(bscInfoVO.getInsCode())
                    ){
                        firstPct = DecimalUtils.mul(DecimalUtils.div(DecimalUtils.sub(VehVal,custFina) ,VehVal),100,15);
                    }
                    /**
                     * 其他机构都可以改首期比例 不做反推
                     */


                }
                logger.info("计算资管二手车首期比例，项目id：{} 客户融资额：{},车辆评估价：{},firstPct: {}",prjId,custFina,VehVal,firstPct);
			}else{
                /**
                 * 我司业务 只有车抵贷倒推首付
                 */
				if(StringUtils.isEmpty(bscInfoVO.getInsCode()) && prjTypCd.equals(PrjBscInfoConstant.PRJ_TYP_CD_CDDYWUL)){
					BaseParamDTO baseParamDTO = new BaseParamDTO();
					baseParamDTO.setChannelCd("CHL0001");
					baseParamDTO.setSysCd("11000");
					baseParamDTO.setServiceCd("SVC0001");
					baseParamDTO.setFrontCd("CHL0001");
					DataResultDTO rcCstBscInfoResult = riskCtrlSingleApiService.searchRcCstBscInfoResult(bscInfoVO.getRcCstBscInfoId(),baseParamDTO);
					String  creditLvl = "";
					if(null!=rcCstBscInfoResult && null!=rcCstBscInfoResult.getData()){
						RiskCtrlSingleResult riskCtrlSingleResult = (RiskCtrlSingleResult) rcCstBscInfoResult.getData();
						creditLvl = riskCtrlSingleResult.getRskLvlCd();//风险级别
						Map<String,String>  map = this.sysDictionaryApiService.searchGroupToMap(CurrentThreadContext.getCurrentSysCd(),CurrentThreadContext.getCurrentOrgCd(),DictionaryConstant.CODE_CDD_QUAT_FST_PCT);
						firstPct = Double.valueOf(map.get(creditLvl));
					}
				}
            }
			if (StringUtils.isNotEmpty(bscInfoVO.getInsCode()) && PrjBscInfoConstant.PRJ_INS_CODE_SYFL.equals(bscInfoVO.getInsCode())&& !"true".equals(editFlag)){
				PrjQuatPrpsVO prpsVO = prjQuatPrpsService.selectById(Long.valueOf(prpsId));
				if (null != prpsVO){
					List<PrjQuatPrpsFeeVO> prjQuatPrpsFeelist = prpsVO.getPrjQuatPrpsFeelist();
					for (PrjQuatPrpsFeeVO fee : prjQuatPrpsFeelist){
						if (PrjQuatPrpsFeeConstant.PRJ_FEE_TYP_FIRST_PRC.equals(fee.getFeeTypCd())){
							firstPct = fee.getFeePct() ;
							break ;
						}
					}
				}
			}
        }
        if (StringUtils.isNotEmpty(prpsCfgId)) {	//如果有方案配置ID 直接查询此方案配置的相关费用信息
            // 首期是否可以编辑
            int isAllowChg = BaseConstant.IS_YESNO_YES ;
            boolean isSetFistPc = false ;
            /**
             * 资管业务
             * 首期比例设置 思路优化 -- 是资管的处理 1、需要设置首期 并且不可编辑  2、需要默认设置首期 可编辑 3、不设置首期
             */
            if(StringUtils.isNotBlank(bscInfoVO.getInsCode())){
                /**
                 * 1、需要设置首期 并且不可编辑 江西金租、兴业金租、三一金租
                 */
                if(PrjBscInfoConstant.PRJ_INS_CODE_JXFL.equals(bscInfoVO.getInsCode())
                        || PrjBscInfoConstant.PRJ_INS_CODE_XYFL.equals(bscInfoVO.getInsCode())
                        || PrjBscInfoConstant.PRJ_INS_CODE_SYFL.equals(bscInfoVO.getInsCode())
                ){
                    isAllowChg = BaseConstant.IS_YESNO_NO;
                    isSetFistPc = true ;
                }
                /**
                 * 2、需要默认设置首期 可编辑
                 */

                /**
                 * 3、不设置首期
                 */
            }else{
                /**
                 * 我司业务
                 * 车抵贷线下 需要设置首付比例 并且不可编辑
                 */
                if(prjTypCd.equals(PrjBscInfoConstant.PRJ_TYP_CD_CDDYWUL)){
                    isSetFistPc = true ;
                    isAllowChg = BaseConstant.IS_YESNO_NO;
                }
            }
            qc.setPrpsCfgId(Long.valueOf(prpsCfgId));
            page.setCondition(qc);
            Pager pager = this.prjQuatPrpsCfgDService.searchListPage(page);
            List<PrjQuatPrpsCfgDVO> list = (List<PrjQuatPrpsCfgDVO>) pager.getResultList();
            List<SysDictionaryDTO> sysDictionaryDTOList = this.sysDictionaryApiService.searchGroup(CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd(), DictionaryConstant.CODE_PRJ_QUAT_FEE_TYP_CD);
            if(CollectionUtils.isNotEmpty(list)){
				InsRouteBscInfoVO insRouteBscInfoVO = this.insRouteBscInfoService.searchListByPrjId(Long.valueOf(prjId));
				String isVisit = insRouteBscInfoVO.getIsVisit();
				List<InsRoutePrpsFeeVO> insRoutePrpsFeeVOList = new ArrayList<InsRoutePrpsFeeVO>();
				if(insRouteBscInfoVO != null){
					insRoutePrpsFeeVOList = insRouteBscInfoVO.getInsRoutePrpsFeeVOList();
				}
				List<InsRoutePrdInfoVO> insRoutePrdInfoVOList = insRouteBscInfoVO.getInsRoutePrdInfoVOList();
				Double mediationFeeAmtSum = 0d;
				if(CollectionUtils.isNotEmpty(insRoutePrdInfoVOList)){
					for (InsRoutePrdInfoVO insRoutePrdInfoVO : insRoutePrdInfoVOList) {
						mediationFeeAmtSum += DecimalUtils.convertFenToYuan(insRoutePrdInfoVO.getMediationFeeAmt()*insRoutePrdInfoVO.getPrdQty());
					}
				}
				Double actAmt = 0d;
				boolean fee76 = false;
				boolean fee78 = false;
                for (PrjQuatPrpsCfgDVO prjQuatPrpsCfgDVO : list) {
                    String feeTypCd = prjQuatPrpsCfgDVO.getFeeTypCd();
                    for (SysDictionaryDTO sysDictionaryDTO : sysDictionaryDTOList) {
                        String code = sysDictionaryDTO.getCode();
                        if(code.equals(feeTypCd)){
                            if(sysDictionaryDTO.getIsSysDef().equals(BaseConstant.IS_YESNO_YES)){
                                prjQuatPrpsCfgDVO.setFlag(BaseConstant.IS_YESNO_YES);
                                prjQuatPrpsCfgDVO.setFlagNm(BaseConstant.IS_YESNO_YES_NM);
                            }
                        }
                    }
					/**
					 * 设置首期比例
					 */
					if(prjQuatPrpsCfgDVO.getFeeTypCd().equals(PrjQuatPrpsFeeConstant.PRJ_FEE_TYP_FIRST_PRC)){
						if(isSetFistPc){
							prjQuatPrpsCfgDVO.setFeePct(firstPct);
							/*prjQuatPrpsCfgDVO.setFeePctMin(firstPct);
							prjQuatPrpsCfgDVO.setFeePctMax(firstPct);*/
							prjQuatPrpsCfgDVO.setIsAllowChg(isAllowChg);
						}
					}
					if(StringUtils.isNotEmpty(feeTypCd)
							&& (PrjQuatPrpsFeeConstant.FEE_TYP_CD_01.equals(feeTypCd)
							|| PrjQuatPrpsFeeConstant.FEE_TYP_CD_02.equals(feeTypCd))){
						if(CollectionUtils.isNotEmpty(insRoutePrpsFeeVOList)){
							for (InsRoutePrpsFeeVO insRoutePrpsFeeVO : insRoutePrpsFeeVOList) {
								if(PrjQuatPrpsFeeConstant.FEE_TYP_CD_01.equals(insRoutePrpsFeeVO.getFeeTypCd())){
									actAmt = insRouteBscInfoVO.getContAmt() - insRoutePrpsFeeVO.getFeeAmt();
								}
							}
							for (InsRoutePrpsFeeVO insRoutePrpsFeeVO : insRoutePrpsFeeVOList) {
								if(feeTypCd.equals(insRoutePrpsFeeVO.getFeeTypCd())){
									if(null!=insRoutePrpsFeeVO.getFeeAmt()){
										prjQuatPrpsCfgDVO.setFixedAmt(DecimalUtils.round(insRoutePrpsFeeVO.getFeeAmt(),0));
									}
									if(null!=insRoutePrpsFeeVO.getFeePct() && insRoutePrpsFeeVO.getFeePct().doubleValue() != 0){
										prjQuatPrpsCfgDVO.setFeePct(insRoutePrpsFeeVO.getFeePct());
									}
									if(null!=insRoutePrpsFeeVO.getCntWayCd()){
										prjQuatPrpsCfgDVO.setCntWayCd(insRoutePrpsFeeVO.getCntWayCd());
									}
									if(null!=insRoutePrpsFeeVO.getIsFixedAmt()){
										prjQuatPrpsCfgDVO.setIsFixedAmt(insRoutePrpsFeeVO.getIsFixedAmt());
									}
									prjQuatPrpsCfgDVO.setIsRoute(BaseConstant.IS_YESNO_YES);
									if(PrjQuatPrpsFeeConstant.FEE_TYP_CD_02.equals(feeTypCd)){
										if(StringUtils.isNotBlank(insRoutePrpsFeeVO.getCalBaseCd())
												&& !((insRoutePrpsFeeVO.getCalBaseCd()).equals(prjQuatPrpsCfgDVO.getCalBaseCd()))){
											if(PrjQuatPrpsConstant.CODE_CAL_BASE_CONTRACT.equals(prjQuatPrpsCfgDVO.getCalBaseCd())){
												if(null!=insRoutePrpsFeeVO.getFeeAmt()){
													prjQuatPrpsCfgDVO.setFeePct(DecimalUtils.div(insRoutePrpsFeeVO.getFeeAmt(),insRouteBscInfoVO.getContAmt(),10)*100);
												}
											}else if(PrjQuatPrpsConstant.CODE_CAL_BASE_FINANCING.equals(prjQuatPrpsCfgDVO.getCalBaseCd())){
												prjQuatPrpsCfgDVO.setFeePct(DecimalUtils.div(insRoutePrpsFeeVO.getFeeAmt(),actAmt,10)*100);
											}
										}
									}
								}
							}
						}
					}
                    //处理费用金额
                    if(null!=prjQuatPrpsCfgDVO.getFixedAmt()){
                        prjQuatPrpsCfgDVO.setFixedAmt(DecimalUtils.div(prjQuatPrpsCfgDVO.getFixedAmt(), 100));
                    }
					if(PrjQuatPrpsFeeConstant.FEE_TYP_CD_76.equals(feeTypCd)){
						fee76 = true;
						prjQuatPrpsCfgDVO.setFixedAmt(mediationFeeAmtSum);
						if(PrjBscInfoConstant.PRJ_TYP_CD_CDDYWUL.equals(prjTypCd) || PrjBscInfoConstant.PRJ_TYP_CD_ESCJYD.equals(prjTypCd) || PrjBscInfoConstant.PRJ_TYP_CD_OWNJYD.equals(prjTypCd)){
							prjQuatPrpsCfgDVO.setCntWayCd(PrjQuatPrpsConstant.CODE_PRJ_QUAT_CNT_WAY_CONT);
							prjQuatPrpsCfgDVO.setCntWayCdNm("计入合同额");
							prjQuatPrpsCfgDVO.setIsAllowChg(BaseConstant.IS_YESNO_NO);
						}else{
							prjQuatPrpsCfgDVO.setCntWayCd(PrjQuatPrpsConstant.CODE_PRJ_QUAT_CNT_WAY_OTH);
							prjQuatPrpsCfgDVO.setCntWayCdNm("其他费用");
						}
						prjQuatPrpsCfgDVO.setIsFixedAmt(BaseConstant.IS_YESNO_YES);
						prjQuatPrpsCfgDVO.setIsFixedAmtNm("是");
					}
					if(PrjQuatPrpsFeeConstant.FEE_TYP_CD_78.equals(feeTypCd)){
						fee78 = true;
						prjQuatPrpsCfgDVO.setFixedAmt(0d);
						prjQuatPrpsCfgDVO.setCntWayCd(PrjQuatPrpsConstant.CODE_PRJ_QUAT_CNT_WAY_DOWNPAY);
						prjQuatPrpsCfgDVO.setCntWayCdNm("计入首期款");
						prjQuatPrpsCfgDVO.setIsFixedAmt(BaseConstant.IS_YESNO_YES);
						prjQuatPrpsCfgDVO.setIsFixedAmtNm("是");
					}
                }
				if(mediationFeeAmtSum != 0 && !fee76){
					PrjQuatPrpsCfgDVO prjQuatPrpsCfgDVO = new PrjQuatPrpsCfgDVO();
					prjQuatPrpsCfgDVO.setPrpsCfgId(list.get(0).getPrpsCfgId());
					prjQuatPrpsCfgDVO.setFeeTypCd(PrjQuatPrpsFeeConstant.FEE_TYP_CD_76);
					prjQuatPrpsCfgDVO.setFeeTypCdNm("调节费");
					prjQuatPrpsCfgDVO.setIsAllowChg(BaseConstant.IS_YESNO_YES);
					prjQuatPrpsCfgDVO.setIsAllowChgNm("是");
					prjQuatPrpsCfgDVO.setIsSysDef(BaseConstant.IS_YESNO_NO);
					prjQuatPrpsCfgDVO.setIsSysDefNm("否");
					prjQuatPrpsCfgDVO.setFixedAmt(mediationFeeAmtSum);
					if(PrjBscInfoConstant.PRJ_TYP_CD_CDDYWUL.equals(prjTypCd) || PrjBscInfoConstant.PRJ_TYP_CD_ESCJYD.equals(prjTypCd) || PrjBscInfoConstant.PRJ_TYP_CD_OWNJYD.equals(prjTypCd)){
						prjQuatPrpsCfgDVO.setCntWayCd(PrjQuatPrpsConstant.CODE_PRJ_QUAT_CNT_WAY_CONT);
						prjQuatPrpsCfgDVO.setCntWayCdNm("计入合同额");
						prjQuatPrpsCfgDVO.setIsAllowChg(BaseConstant.IS_YESNO_NO);
					}else{
						prjQuatPrpsCfgDVO.setCntWayCd(PrjQuatPrpsConstant.CODE_PRJ_QUAT_CNT_WAY_OTH);
						prjQuatPrpsCfgDVO.setCntWayCdNm("其他费用");
					}
					prjQuatPrpsCfgDVO.setIsFixedAmt(BaseConstant.IS_YESNO_YES);
					prjQuatPrpsCfgDVO.setIsFixedAmtNm("是");
					list.add(prjQuatPrpsCfgDVO);
				}
				if(BaseConstant.IS_YESNO_YES_STR.equals(isVisit) && !fee78){
					PrjQuatPrpsCfgDVO prjQuatPrpsCfgDVO = new PrjQuatPrpsCfgDVO();
					prjQuatPrpsCfgDVO.setPrpsCfgId(list.get(0).getPrpsCfgId());
					prjQuatPrpsCfgDVO.setFeeTypCd(PrjQuatPrpsFeeConstant.FEE_TYP_CD_78);
					prjQuatPrpsCfgDVO.setFeeTypCdNm("家访费");
					prjQuatPrpsCfgDVO.setIsAllowChg(BaseConstant.IS_YESNO_YES);
					prjQuatPrpsCfgDVO.setIsAllowChgNm("是");
					prjQuatPrpsCfgDVO.setIsSysDef(BaseConstant.IS_YESNO_NO);
					prjQuatPrpsCfgDVO.setIsSysDefNm("否");
					prjQuatPrpsCfgDVO.setFixedAmt(0d);
					prjQuatPrpsCfgDVO.setCntWayCd(PrjQuatPrpsConstant.CODE_PRJ_QUAT_CNT_WAY_DOWNPAY);
					prjQuatPrpsCfgDVO.setCntWayCdNm("计入首期款");
					prjQuatPrpsCfgDVO.setIsFixedAmt(BaseConstant.IS_YESNO_YES);
					prjQuatPrpsCfgDVO.setIsFixedAmtNm("是");
					list.add(prjQuatPrpsCfgDVO);
				}
            }
            listPage = new ListPageVO<PrjQuatPrpsCfgDVO>(list, pager.getTotalCount());
			logger.info("查询数据完成. DATA:" + JSONObject.toJSONString(page));
        }
        return listPage;
    }

	@ResponseBody
	@RequestMapping("/setIsLowBiz.do")
	public DataResultVO setIsLowBiz(@RequestParam("prjId")Long prjId , @RequestParam("isLowBiz") Integer isLowBiz){
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "修改成功!");
		logger.info("修改是否低息标识params:[prjId:" + prjId + ",isLowBiz:" + isLowBiz+"]");
		PrjQuatPrpsQueryCondition condition = new PrjQuatPrpsQueryCondition();
		condition.setPrjId(prjId);
		condition.setIsDel(BaseConstant.IS_YESNO_NO);
		List<PrjQuatPrpsVO> prjQuatPrpsVOS = prjQuatPrpsService.searchList(condition);
		Integer modify = 0 ;
		for (PrjQuatPrpsVO quatPrpsVO :prjQuatPrpsVOS){
			quatPrpsVO.setIsLowBiz(isLowBiz);
			boolean b = prjQuatPrpsService.modifyPrjQuatPrps(quatPrpsVO);
			if (b){
				modify ++ ;
			}
		}
		logger.info("修改是否低息标识result:" + modify);
		if (modify == prjQuatPrpsVOS.size()){
			result.setData(modify);
		}else{
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setData(modify);
			result.setInfo("修改失败");
		}
		return result ;
	}


	/**
	 * description 校验选中的机构模式是否与厂商报价器的机构的模式是否一致
	 * @param prjBscInfoVO
	 */
	private boolean validatorCheckedInsCodeModel(PrjBscInfoVO prjBscInfoVO) {
		//得到insCode机构编码
		String insCode = prjBscInfoVO.getInsCode();
        logger.info("【validatorCheckedInsCodeModel】方法，选择的机构是："+insCode);

		//得到报价器的id,可以从报价器的表查找保存的insCode(机构)和模式
		Long calId = prjBscInfoVO.getCalId();
        logger.info("【validatorCheckedInsCodeModel】方法，报价器方案Id："+calId);

		//获取一条数据字典对象，用来判断是否有模式
		SysDictionaryDTO sysDictionaryDTO = this.sysDictionaryApiService.getCode(CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd(), PrjPlcyIndexConstant.PLCY_VEH_TYP_CD10, insCode);
        logger.info("【validatorCheckedInsCodeModel】方法，获取数据字典中："+sysDictionaryDTO.toString());
		logger.info("【validatorCheckedInsCodeModel】方法，获取数据字典中的机构："+sysDictionaryDTO.getCode() + ",模式:"+sysDictionaryDTO.getPCode());

		//获取报价器表的信息
		CalQuatPrpsVO calQuatPrpsVO = this.calQuatPrpsService.selectCalQuatProsAndDetailById(calId);
        logger.info("【validatorCheckedInsCodeModel】方法，报价器表的机构："+calQuatPrpsVO.getInsCode() + ",模式:"+calQuatPrpsVO.getInsQuatTyp());

		//判断模式不为空的情况下，与厂商报价器的模式是否一致
		if (null != sysDictionaryDTO && null != calQuatPrpsVO) {
			 if (StringUtils.isNotBlank(sysDictionaryDTO.getPCode()) && StringUtils.isNotBlank(calQuatPrpsVO.getInsQuatTyp())) {
                 logger.info("【validatorCheckedInsCodeModel】方法，预选机构和厂商报价是否一致："+sysDictionaryDTO.getPCode().equals(calQuatPrpsVO.getInsQuatTyp()));

                 return sysDictionaryDTO.getPCode().equals(calQuatPrpsVO.getInsQuatTyp());
			 }

			 if (null == sysDictionaryDTO.getPCode() && null == calQuatPrpsVO.getInsQuatTyp()) {
				 logger.info("选的机构不支持厂商");
			 }
		}
		return false;
	}


	/**
	 * @param prjQuatPrps 报价方案数据
	 * @description 在保存之前校验下
	 */
	private void addQuatPrpsBeforeValidate(PrjQuatPrpsVO prjQuatPrps) {
		/*
		 * 重卡事业部 传统/城配
		 * 我司 报价方案名称为重卡灵活报价方案
		 * 校验捆绑租金服务的值，如果选择的是，那么校验该项目下的主车数量
		 * 得出捆绑租金补助服务的车辆费用合计:项目下主车数量*1380
		 */
		Long prjId = prjQuatPrps.getPrjId();
		PrjBscInfoVO prjBscInfoVO = prjBscInfoService.selectById(prjId);
		String buOrgCd = prjBscInfoVO.getBuOrgCd();
		String prjTypCd = prjBscInfoVO.getPrjTypCd();
		String prpsCfgNm = prjQuatPrps.getPrpsCfgNm();
		Long prpsCfgId = prjQuatPrps.getPrpsCfgId();
		logger.info("项目id:{},在保存之前校验的，项目的事业部:{},项目类型:{},报价方案名字:{},配置方案id:{}",prjId,buOrgCd,prjTypCd,prpsCfgNm,prpsCfgId);

		List<PrjQuatPrpsFeeVO> prjQuatPrpsFeelist = prjQuatPrps.getPrjQuatPrpsFeelist();
		logger.info("项目id:{},报价方案费用项数据:{}",prjId,JSON.toJSONString(prjQuatPrpsFeelist));
		// 重卡事业部 传统/城配
		if (PrjBscInfoConstant.CODE_BU_ORG_CD_ZK.equals(buOrgCd) && StringUtils.isNotBlank(prjTypCd) && (PrjBscInfoConstant.PRJ_TYP_CD_CPYW.equals(prjTypCd)  || PrjBscInfoConstant.PRJ_TYP_CD_CTYW.equals(prjTypCd))) {
			if(PrjBscInfoConstant.COMPENSATORY_TYPE_2.equals(prjBscInfoVO.getCompensatoryType())){
				if (StringUtils.isEmpty(prjQuatPrps.getChlDpstPwayCd()) || prjQuatPrps.getChlDpstPwayCd().equals(" ")){
					throw new BaseException("请选择渠道保证金退还方式") ;
				}
			}
			// 我司
			if (StringUtils.isBlank(prjBscInfoVO.getInsCode())) {
				// 报价方案名称为重卡灵活报价方案
				if (StringUtils.isNotBlank(prpsCfgNm) && "重卡灵活报价方案".equals(prpsCfgNm)) {

					if (Objects.equals(prjQuatPrps.getRentAllowanceService(), 2)) {
						throw new BaseException("请选择是否捆绑租金补助服务!");
					}

					// 是否绑定租金补助服务,选择的是
					if (BaseConstant.IS_YESNO_YES == prjQuatPrps.getRentAllowanceService().intValue()) {
						Double firstAmt = 0d;
						// 获取费用项的首期金额
						for (PrjQuatPrpsFeeVO prjQuatPrpsFeeVO : prjQuatPrpsFeelist) {
							if(prjQuatPrpsFeeVO.getFeeTypCd().equals(PrjQuatPrpsConstant.CODE_FEE_WAY_TYPE_DOWNPAY)) {
								firstAmt = prjQuatPrpsFeeVO.getFeeAmt();
								break;
							}
						}
						logger.info("项目id:{},租金补助服务,首期金额:{}",prjId,firstAmt);

						PrjPrdBscInfoQueryCondition prjPrdQc = new PrjPrdBscInfoQueryCondition();
						prjPrdQc.setPrjId(Long.valueOf(prjId));
						List<PrjPrdBscInfoVO> prjPrdBscInfoDTOS = this.prjPrdBscInfoService.searchList(prjPrdQc);
						logger.info("项目id:{},租金补助服务,该项目下的产品数量:{},产品数据:{}",prjId,prjPrdBscInfoDTOS.size(),JSON.toJSONString(prjPrdBscInfoDTOS));

						// 主车数量
						int zhuCheAmount = 0;
						if (CollectionUtils.isNotEmpty(prjPrdBscInfoDTOS)) {
							for (PrjPrdBscInfoVO prjPrdBscInfoDTO : prjPrdBscInfoDTOS) {
								if (!(PrjPrdBscInfoConstant.PRD_TYP_CD_9.equals(prjPrdBscInfoDTO.getPrdTypCd()))) {
									if (prjPrdBscInfoDTO.getPrdQty().intValue() == 1) {
										zhuCheAmount++ ;
									} else {
										zhuCheAmount += prjPrdBscInfoDTO.getPrdQty().intValue();
									}
								}
							}
						}

						// 查询租金补助服务费的金额 从字典表里查
						String rentAllowanceServiceFeeStr = "0";
						List<SysDictionaryDTO> sysDictionaryDTOList = this.sysDictionaryApiService.searchGroup(CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd(), DictionaryConstant.CODE_PRJ_QUAT_FEE_TYP_CD);
						logger.info("项目id:{},租金补助服务,查询出来的【PRJ0039】费用项类型数据:{}",prjId,JSON.toJSONString(sysDictionaryDTOList));

						if (CollectionUtils.isNotEmpty(sysDictionaryDTOList)) {
							for (SysDictionaryDTO sysDictionaryDTO : sysDictionaryDTOList) {
								if (PrjQuatPrpsFeeConstant.FEE_TYP_CD_116.equals(sysDictionaryDTO.getCode())) {
									// 取出租金补助服务费
									rentAllowanceServiceFeeStr = sysDictionaryDTO.getCodeDesc();
									break;
								}
							}
						}
						logger.info("项目id:{},租金补助服务,查询出来的单车租金补助服务费:{}",prjId,rentAllowanceServiceFeeStr);

						Double rentAllowanceServiceFeeSum = zhuCheAmount * (Double.parseDouble(rentAllowanceServiceFeeStr));
						logger.info("项目id:{},租金补助服务,该项目下主车数量:{},捆绑租金补助的车辆费用合计:{}",prjId,zhuCheAmount,rentAllowanceServiceFeeSum);

						// 主车的数量大于0 才行
						if (zhuCheAmount > 0) {
							if (DecimalUtils.div(firstAmt,100) < rentAllowanceServiceFeeSum) {
								throw new BaseException("提示：项目首期金额不能小于租金补助服务费" + rentAllowanceServiceFeeSum + "元");
							}
						}
					}
				}
			} else {
				// 资管
				if (Objects.equals(prjQuatPrps.getRentAllowanceService(), 2)) {
					throw new BaseException("请选择是否捆绑租金补助服务!");
				}
			}
		}
	}
}

